Here is the code I am working on...
Here Name.dat is empty file...
# Library Management System
import time
import pickle
import csv
print("Welcome to the Library Management System")
time.sleep(0.3)
print("Hello there",end="")
print(".",end="")
time.sleep(0.5)
print(".",end="")
time.sleep(0.5)
print(".")
time.sleep(0.5)
while True:
try:
print("If you are new user press 1 to continue::")
print("If you are an existing user press 2 to continue::")
print("If you want to exit press 3::")
time.sleep(0.5)
n=int(input("Enter your choice::"))
except:
print("Only integer values.")
try:
if n==1:
print("here")
name_list=[]
print("here")
f=open("Name.dat","rb+")
print("here")
s=pickle.load(f)
print("here")
if len(s)==0:
pass
else:
for i in s:
name_list.append(i)
f=open("Name.dat","ab+")
l=[]
user=input("Enter username::")
while True:
truth=1
if len(name_list)==0:
pass
else:
for i in range(len(name_list)):
if user==name_list[i][0]:
truth=0
if truth==1:
break
user=input("Enter username::")
l.append(user)
ps=input("Enter password::")
l.append(ps)
l.append([])
pickle.dump(l,f)
f.close()
print("Your account has been successfully made.")
elif n==2:
f=open("Name.dat","rb+")
b=int(input("Enter the password::"))
try:
while True:
s=pickle.load(f)
if s[1]==b:
print("Hello",s[0])
print("What do you want to do?")
print("Enter 1 to borrow a book::")
print("Enter 2 to return a book::")
except EOFError:
f.close()
elif n==3:
f=open("csv_file.csv",'r')
csvr=csv.reader(f)
for line in csvr:
#copying data into a temporary storage area from csv file
print(line)
f.close()
break
elif n>3:
print("Wrong input")
except IOError:
print("swomething")
None
The problem occurs when I enter 1 in the python shell...
Welcome to the Library Management System
Hello there...
If you are new user press 1 to continue::
If you are an existing user press 2 to continue::
If you want to exit press 3::
Enter your choice::1
here
here
here
Traceback (most recent call last):
File "C:\Users\CCFFIN\AppData\Local\Programs\Python\Python38\Python big big c project\LBS.py", line 30, in <module>
s=pickle.load(f)
EOFError: Ran out of input
The error is in pickle .load but I have no idea why that is happening
is it because Name.dat is empty?
What i basically want is something like this without any exceptions
Welcome to the Library Management System
Hello there...
If you are new user press 1 to continue::
If you are an existing user press 2 to continue::
If you want to exit press 3::
Enter your choice::1
here
here
here
here
Enter username::
Ps note that I printed here to identify the error so that is not necessary
csv_file is not empty and has 51 lists in it
also please tell why dump is not working and why is there an EofError
Thank you in advance