所以我在这里制作了一个小应用程序,并且我尝试了块(因为我需要查看文件是否已经存在或应该创建)。虽然...我的尝试块由于某种原因而重复!我完全不 知道为什么会这样。请帮忙?此外,该文件创建良好:) 代码:
import sys
import time
Version = "V0.1"
def user():
PISBNdat = open("PISBN.dat", "w")
PISBNdat.write(Version)
cuser = raw_input("Please enter account username!")
for line in PISBNdat:
print "Test"
if cuser in line:
print("User already exists! Try again!")
user()
def start():
print "Hello and welcome to Plaz's PISBN!"
print "Opening file..."
time.sleep(0.8)
try:
fin = open("PISBN.dat", "r")
print "Success!"
fin.close()
user()
except:
time.sleep(0.5)
print "Did not recognize/find file!"
time.sleep(0.1)
print "Creating file!"
time.sleep(0.5)
try:
fout = open("PISBN.dat", "w")
print "Success!"
fout.close()
user()
except:
print "Failed!"
exit()
start()
这是输出...:
Hello and welcome to Plaz's PISBN!
Opening file...
Did not recognize/find file!
Creating file!
Success!
Please enter account username! [This is what I entered: Plazmotech]
Failed!
现在很明显,因为它说“失败!”,这意味着它正在运行我的尝试块......因为那是它唯一可以输出“失败!”的地方 所以请在这里帮忙!