12th Standard Syllabus & Materials
12th Standard
TN 12th Computer Applications மின்னணு தரவு பரிமாற்றம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின் - வணிக பாதுகாப்பு அமைப்புகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின்னணு செலுத்தல் முறைகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின் - வணிகம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications திறந்த மூல கருத்துருக்கள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications வலையமைப்பு வடமிடல் Sample Question Papers Study Material - QB365 Set A

Published on: 03/12/2019
Python and CSV Files
Download Tamil Nadu 12th Standard Computer Science question papers, model tests, one-mark questions, important questions, and public exam papers in PDF format. Free study materials and answer keys for TN State Board students.
Questions + Answers key
Take MCQ Computer Science Test

1.
While reading CSV file in text mode, the data would be in the format
numbers
characters
strings
float
2.
Which of the following built-in function Python has to open a file?
read ()
open ()
reader ()
openfile ()
3.
CSV means
Condition separated values
Colon separated values
C++ solution values
Comma separated values
4.
Which of the following is a string used to terminate lines produced by writer()method of csv module?
Line Terminator
Enter key
Form feed
Data Terminator
5.
A CSV file is also known as a ….
Flat File
3D File
String File
Random File
6.
Write a note is register dialect ( ) method?
7.
What is the purpose of using 'with' statement along with open ( )?
8.
What take the three models in which CSV file can be opened?
9.
How will you sort more than one column from a csv file?Give an example statement.
10.
What is use of next() function?
11.
Write a program to create a new normal CSV file to store data.
12.
Write the syntax of reader( ).
13.
How will you save the CSV file in MS-Excel?
14.
Write a Python program to read a CSV file with default delimiter comma (,).
15.
Write a Python program to modify an existing file.
16.
Write a Python program to write a CSV File with custom quotes.
17.
Tabulate the different mode with its meaning.
1.
(c)
strings
2.
(b)
open ()
3.
(d)
Comma separated values
4.
(a)
Line Terminator
5.
(a)
Flat File
6.
(i) The whitespaces can be removed, by registering new dialects using csv.register_ dialect ( ) class of csv module.
(ii) A dialect describes the format of the csv file that is to be read, In dialects the parameter "skipinitialspace" is used for removing whitespaces after the delimiter.
7.
If an exception occurs when you are performing some operation with the file, the code exits without closing the file. The best way to do this is using the "with" statement. This ensures that the file is closed when the block inside with is exited.
8.
Read 'r', write 'w' or append 'a'.
9.
To sort by more than one column you can use itemgetter with multiple indices:
operator.itemgetter
Example:
sortedlist = sorted (data, key = operator. itemgetter(1))
10.
The row heading is get sorted, to avoid the first row should be skipped. This is can be done by using the command "next( )".
11.
Import csv
csvData = [['Student, 'Age'], [Dhanush', '17'], ['Kalyani', '18'], ['Ram', '15']]
with open('c:\\pyprg\\ch13\\Pupil.csv', 'w') as CF:
writer = csv.writer(CF) # CF is the file object
writer.writerows(csvData) # csvData is the List name
CF.close( )
12.
'The syntax for csv.reader() is
csv.reader(fileobject,delimiter,fmtparams)
where
(i) file object: passes the path and the mode of the file.
(ii) delimiter: an optional parameter containing the standard dilects like , | etc can be omitted
(iii) fmtparams: optional parameter which help to override the default values of the dialects like skipinitialspace, quoting etc. Can be omitted.
13.
To create a CSV file using Microsoft Excel, launch Excel and then open the file you want to save in CSV format. For example. below is the data contained in our sample Excel worksheet:
Once the data is entered in the worksheet, select File ⟶ Save As option, and for the "Save as type option" select CSV (Comma delimited) or type the file name along with extension .csv.
14.
Program: To read a csv file with comma (,)
#importing csv
import csv
#opening the csv file which is in different location with read mode
with open('c:\\Pyprg\ \sample1.csv', 'r') as F:
#other way to open the file is
f=('C:\\pyprg\\sample1.csv', 'r')
reader = csv.reader(F))
#printing each line of the Data row by row.
print (row)
F. close( )
Output:
['SNO','NAME', 'CITY']
['12101', 'RAM', 'CHENNAI']
['12102', 'LAVANYA' "TIRUCHY']
['12103', 'LAKSHMAN', 'MADURAI']
15.
Program: To modify an existing file
import csv
row = ['3: 'Meena','Bangalore']
with open('Student.csv', 'r') as read file:
reader = csv.reader (read File)
lines = list (reader)
lines [3] = row
with open ('Student.csv', 'w') as write file:
# returns the writer object which converts the user data with delimiter.
writer = csv.writer(writefile)
#writerows() method writes multiple rows to a csv file
writer. writerows(lines)
readFile.close()
writeFile.close()
Output:
| Roll No | Name | City |
| 1. | Harshini, | Chennai |
| 2. | Adhith, | Mumbai |
| 3. | Meena, | Bangalore |
| 4. | Egiste | Tiruchy |
| 5. | Venkat, | Madurai |
16.
We can write the csv file with quotes, by registering new dialects using csv.register_dialect() class of csv module.
Program:
import csv
info = [['SNO: 'Person: 'DOB'],
['1', 'Madhu,' '18/12/2001'],
['2', 'Sowmya', '19/2/1998'],
['3', 'Sangeetha', '20/3/1999'],
['4', 'Eshwar', '21/4/2000'],
['5', 'Anand', '22/5/2001']]
csv.register_dialect('MyDialect',quoting=csv.QUOTE_ALL)
with open('c:\\pyprg\\ch13\\person.csv', 'w') as f:
writer = csv.writer(f, dialect='myDialect')
for row in info:
writer. writerow(row)
f.close()
Output
file: "Person.csv"
"SNO","Person", "DOB", "1", "Madhu", "18/12/2001"
"2, "Sowmya", "19/2/1998", "3", "Sangeetha",
"20/3/1999", "4", "Eshwar", "21/4/2000"
"5", "Anand", "22/5/2001".
17.
| Python file modes | Description |
|---|---|
| 'r' | open a file for reading (default) |
| 'w' | Open a file for writing. Creates a new file if it does not exist or truncates the file if it exists. |
| 'x' | Open a file for exclusive creation. If the file already exists, the operation fails. |
| 'a' | Open for appending at the end of the file without truncating it. Creates a new file if it does not exist. |
| 't' | Open in text mode. default |
| 'b' | Open in binary mode. |
| '+' | Open a file for updating (reading and Writing) |
12th Standard Syllabus & Materials
12th Standard
TN 12th Computer Applications களப்பெயர் முறைமை (DNS) Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications வலையமைப்பு எடுத்துக்காட்டுகள் மற்றும் நெறிமுறைகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications கணினி வலையமைப்பு ஓர் அறிமுகம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications PHP-உடன் MySQL-ஐ இணைத்தல் Sample Question Papers Study Material - QB365 Set A
Tamilnadu Stateboard 12th Standard Subjects

Maths

Chemistry

Physics

Biology

Computer Science

Business Maths and Statistics

Economics

Commerce

Accountancy

History

Computer Applications

Biology

Computer Technology

Computer Applications

Computer Science

Business Maths and Statistics

Commerce

Economics

Maths

Chemistry

Physics

Computer Technology

History

Accountancy

Tamil

English

French
Tamilnadu Stateboard Standards