Advertisements
Advertisements
Question
Write a Python program to read a CSV file with default delimiter comma (,).
Solution
Coding:
#importing csv
import csv
#opening the csv file which is in different location with read mode with opent(‘c.\\pyprg\\samplel-csv’, ‘r’) as F:
#other way to open the file is f= (‘c:\ \ pyprg\ \ samplel.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′,’ LAV ANYA’,’ TIRCHY’]
[‘12103’, ‘LAKSHMAN’, ‘MADURAI’]
APPEARS IN
RELATED QUESTIONS
Mention the two ways to read a CSV file using Python.
Mention the default modes of the File.
What is the difference between the write mode and append mode?
What is the difference between reader() and DictReader() function?
Write the different methods to read a File in Python.
Write a Python program to write a CSV File with custom quotes.
Write the rules to be followed to format the data in a CSV file.
What is the advantage of using a CSV file for permanent storage? Write a Program in Python that defines and calls the following user-defined functions:
- ADD() - To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of a list with field elements such as empid, name, and mobile to store an employee id, employee name, and employee salary respectively.
- COUNTR() - To count the number of records present in the CSV file named ‘record.csv’.
Give any one point of difference between a binary file and a CSV file. Write a Program in Python that defines and calls the following user-defined functions:
- add() - To accept and add data of an employee to a CSV file ‘furdata.csv’. Each record consists of a list with field elements such as fid, fname, and fprice to store furniture id, furniture name, and furniture price respectively.
- search() - To display the records of the furniture whose price is more than 10000.
Select the correct output of the code:
S="Amrit Mahotsav @ 75"
A=S.partition (" ")
print(a)