- Notifications
You must be signed in to change notification settings - Fork 638
Expand file tree
/
Copy pathP54_PythonCSV.py
More file actions
Latest commit
30 lines (25 loc) · 1.18 KB
/
Copy pathP54_PythonCSV.py
File metadata and controls
30 lines (25 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Author: OMKAR PATHAK
# In this example we will see how to use CSV files with Python
# csv.QUOTE_ALL = Instructs writer objects to quote all fields.
# csv.QUOTE_MINIMAL = Instructs writer objects to only quote those fields which contain special characters such
# as delimiter, quotechar or any of the characters in lineterminator.
# csv.QUOTE_NONNUMERIC = Instructs writer objects to quote all non-numeric fields.
# Instructs the reader to convert all non-quoted fields to type float.
# csv.QUOTE_NONE = Instructs writer objects to never quote fields.
importcsv
defcsvRead(filePath):
withopen(filePath) asfd:
reader=csv.reader(fd, delimiter=',')
forrowinreader:
print(row[0] +' '+row[1])
defcsvWrite(filePath, data):
withopen(filePath, 'a') asfd:
writer=csv.writer(fd, delimiter=',', quoting=csv.QUOTE_NONNUMERIC)
writer.writerow(data)
if__name__=='__main__':
# data = ['Firstname', 'Lastname']
# csvWrite('example.csv', data)
userInput=input('What is your Fullname? ')
userInput=userInput.split(' ')
csvWrite('example.csv', userInput)
csvRead('example.csv')