0% found this document useful (0 votes)
0 views58 pages

Full File Handling Tutorial

The document provides Python code for managing courier records using two user-defined functions: COURIER_ADD and COURIER_SEARCH. COURIER_ADD allows users to input courier details and save them to a CSV file, while COURIER_SEARCH retrieves and displays records based on a specified destination. The code includes functionality for adding records and searching through the CSV file for specific entries.

Uploaded by

amiteshyadav9554
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views58 pages

Full File Handling Tutorial

The document provides Python code for managing courier records using two user-defined functions: COURIER_ADD and COURIER_SEARCH. COURIER_ADD allows users to input courier details and save them to a CSV file, while COURIER_SEARCH retrieves and displays records based on a specified destination. The code includes functionality for adding records and searching through the CSV file for specific entries.

Uploaded by

amiteshyadav9554
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 58

Python Code:

OUTPUT:

As soon as your program terminates this data


will be erased from the memory.
Notepad
Absolute Path of the File
Pickling
Unpickling
Blank Line….

Blank Line is REMOVED


Write a program in Python that defines and calls the following user defined functions:
(i)COURIER_ADD : It takes the values from the user and adds the details to a csv file ‘courier.csv’.
Each record consists of a list with field elements as cid, s_name, Source, destination to store Courier ID, Sender name,
Source & Destination address respectively.
(ii) COURIER_SEARCH(): Takes the destination as the input and display all the courier records going to that destination.
import csv
Courier_List=[]
def COURIER_ADD():
fw_csv = open("courier.csv","w",newline='')
choice="y"
while choice=="y":
cid=input("Enter Courier ID")
s_name=input("Enter Senders Name")
source=input("Enter Source Address")
destination=input("Enter Deatination address")
L=[cid,s_name,source,destination]
Courier_List.append(L)
choice=input("Do you want to add more records(y/n)")
print(Courier_List)
csv_writer = csv.writer(fw_csv)
csv_writer.writerows(Courier_List)
fw_csv.close()

def COURIER_SEARCH():
fr_csv = open("courier.csv","r")
destination=input("Enter the destination to be searched")
csv_reader = csv.reader(fr_csv)
for i in csv_reader:
if i[3]== destination:
print(i)
fr_csv.close()

#COURIER_ADD()
COURIER_SEARCH()

You might also like