问题描述
我已经确定,只要有人注册txt文件,就以用户名命名。现在我正在尝试检查dir中是否存在用户名txt文件,这是我尝试过的代码。 我无法检查用户名txt文件是否存在。我尝试了许多比较方式搜索谷歌,但没有运气我已经提到了一些评论。请帮助寻找
def db():
a = (E1.get(),E2.get(),E3.get(),E4.get(),E5.get())
if "./library/"+E1.get() == os.path.isfile("./library/"+E1.get()):
# if E1.get() == os.path.isfile(E1.get()):
# if E1.get()in os.path.isdir("./library/"):
cur.execute("insert into Booking values(?,?,?)",a)
con.commit()
cur.execute("select * from Booking")
a = cur.fetchall()
ab = int(E4.get())
cost=100
ac = ab * cost
messageBox.showinfo("Congratulation!!","Your oreder value is %s" % ac)
print(a)
te.destroy()
os.system("library.py")
else:
print("username invalid")
解决方法
尝试替换下面的行
if "./library/"+E1.get() == os.path.isfile("./library/"+E1.get()):
使用
if os.path.isfile("./library/"+E1.get()):
您可能对return
fn的os.path.isfile()
值感到困惑。