What is a CSV?
Comma Separated Values- (CSV) is a simple file format used to store tabular data, such as a spreadsheet or database. A Comma Separated Values- (CSV) file stores tabular data (numbers and text) in plain text. Each line of the file is a data record. Each record consists of one or more fields, separated by commas.
csv.reader()
csvreader is an iterable object. Hence, .next() method returns the current row and advances the iterator to the next row.
csv.writer()
The file object is named as csvfile. The file object is converted to csv.writer object. We save the csv.writer object as csvwriter.
Program
import csv
with open("user_info.csv", "w") as obj:
fileobj = csv.writer(obj)
fileobj.writerow(["User Id", "password"])
while(True):
user_id = input("enter id: ")
password = input("enter password: ")
record = [user_id, password]
fileobj.writerow(record)
x = input("press Y/y to continue and N/n to terminate the program\n")
if x in "Nn":
break
elif x in "Yy":
continue
with open("user_info.csv", "r") as obj2:
fileobj2 = csv.reader(obj2)
given = input("enter the user id to be searched\n")
for i in fileobj2:
next(fileobj2)
# print(i,given)
if i[0] == given:
print(i[1])
break
Related searches
- Csv in python example
- read csv python pandas
- csv file handling in python
- csv writer python
- import csv python
- read_csv python
- pip install csv
- read specific rows from csv in python pandas
- write a python program to create a csv file by entering user id and password
- write a python program to implement a stack using list.
- create password csv file
- create a binary file with roll number, name and marks. input a roll number and update the marks.
- write a python program to read each row from a given csv file and print a list of strings
- write a program to add employee records into a csv file
- read the given csv file and display the maximum salary
- write a program to read the csv file and display the content