Python Programming and SQL
Python Programming and SQL
'''
3.Create a binary file with the name and roll
2. Read a text file and display the number of number. Search for a given roll number and
vowels/ consonants/ uppercase/ lowercase display the name, if not found display
characters and other than character and digit appropriate message.
in the file.
import pickle
filein = open("file.txt",'r')
#creating the file and writing the data
line = filein.read()
f=open("records.dat", "wb")
srecord={"SROLL":sroll,"SNAME":sname,"SPERC
pickle.dump(["Wakil", 1], f)
":sperc,
pickle.dump(["Tanish", 2], f)
"SREMARKS":sremark}
pickle.dump(["Priyashi", 3], f)
pickle.dump(srecord,Myfile)
pickle.dump(["Kanupriya", 4], f)
pickle.dump(["Aaheli", 5], f)
def Readrecord():
f.close()
with open ('StudentRecord.dat','rb') as
#opeining the file to read contents Myfile:
if flag==False: break
for j in newRecord:
def Modify(roll):
pickle.dump(j,Myfile)
with open ('StudentRecord.dat','rb') as
Myfile:
newRecord=[]
try:
Readrecord()
if found==0:
5. Remove all the lines that contain the
character `a' in a file and write it to another
print("Record not found") file
#Python program to
# using list
f1 = open("file.txt")
f2 = open("copyfile.txt","w") stack = []
f1.close() stack.append('b')
f2.close() stack.append('c')
print(f2.read()) print(stack)
# LIFO order
import csv
fileobj = csv.writer(obj)
fileobj.writerow(["User Id",
"password"])
while(True):
password = input("enter
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
fileobj2 = csv.reader(obj2)
for i in fileobj2:
next(fileobj2)
# print(i,given)
if i[0] == given:
print(i[1])