Computer Science
Write a Python program to read a given CSV file having tab delimiter.
Python File Handling
4 Likes
Answer
Let "example.csv" file contain the following data:
Name Age Gender
Kavya 25 Female
Kunal 30 Male
Nisha 28 Female
import csv
with open("example.csv", 'r', newline='') as file:
reader = csv.reader(file, delimiter='\t')
for row in reader:
print(row)
Output
['Name Age Gender']
['Kavya 25 Female']
['Kunal 30 Male']
['Nisha 28 Female']
Answered By
1 Like
Related Questions
A binary file "Book.dat" has structure [BookNo, Book_Name, Author, Price].
(i) Write a user defined function CreateFile() to input data for a record and add to Book.dat.
(ii) Write a function CountRec(Author) in Python which accepts the Author name as parameter and count and return number of books by the given Author are stored in the binary file "Book.dat"
Write a function Show_words() in python to read the content of a text file 'NOTES.TXT' and display only such lines of the file which have exactly 5 words in them.
Example, if the file contains :
This is a sample file.
The file contains many sentences.
But need only sentences which have only 5 words.Then the function should display the output as :
This is a sample file.
The file contains many sentences.Write a Python program to write a nested Python list to a csv file in one go. After writing the CSV file read the CSV file and display the content.
Write a function that reads a csv file and creates another csv file with the same content, but with a different delimiter.