Python为什么二进制文件空没有被转储

问题描述

这是我正在处理的代码...

这里Name.dat是空文件...

# 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
      

当我在python shell中输入1时出现问题...

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   

错误是在pickle .load中,但是我不知道为什么会发生

是因为Name.dat为空吗?

我基本上想要的是类似这样的东西

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::

请注意,我在这里打印是为了识别错误,因此没有必要

csv_file不为空,其中有51个列表

还请说明为什么转储不起作用以及为什么出现EofError

提前谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)