CSV Modular Type python the built-in modules , for reading and writing CSV file .
TESTQQ . csv File Contents :
|
Serial number |
Name |
Age |
|
1 |
Oh, yes. |
10 |
|
2 |
Baby |
15 |
|
3 |
Size |
17 |
|
4 |
Wait a minute |
19 |
|
5 |
nn |
20 |
|
6 |
Method |
21st |
|
first, from CSV file Read Content
use csv module reader function read " Span style= "FONT-FAMILY:CALIBRI;" lang= "en-us" xml:lang= "en-US" >csv file code :
|
import csv
f = open (' Testqq.csv ', ' RB ')
reader = Csv.reader (f)
for line in Reader:
Print line |
Run Results :
|
>>>
[' \xd0\xf2\xba\xc5 ', ' \xd0\xd5\xc3\xfb ', ' \xc4\xea\xc1\xe4 ']
[' 1 ', ' \xb0\xa1\xb0\xa1 ', ' 10 ']
[' 2 ', ' \xb1\xa6\xb1\xa6 ', ' 15 ']
[' 3 ', ' \xb3\xdf\xb4\xe7 ', ' 17 ']
[' 4 ', ' \xb5\xc8\xb5\xc8 ', ' 19 ']
[' 5 ', ' \xb6\xf7\xb6\xf7 ', ' 20 ']
[' 6 ', ' \xb7\xbd\xb7\xa8 ', ' 21 ']
>>>
|
second, from CSV File Write content
Use writer function to CSV File Write content
|
Import CSV
f = open (' Testqq.csv ', ' WB ')
writer = Csv.writer (f)
Writer.writerow ([' serial number ', ' name ', ' age '])
data = [' AA ', ' BB ', ' CC ']
Writer.writerow (data)
|
program run result testqq.csv file has been written to aa bb cc
CSV Module-python