I am trying to get Python 3.5 to look in a file for a variable. I have tried to convertusername
to str(username)
but to no avail. Here is the offending piece of code:
if str(username) in fi.read():
hasAccount = True
print("found username")
else:
hasAccount = False
print("notfound")
Any ideas? This one has me absolutely baffled. Thanks
P.S. I have already used with open("usernames.txt", "a+")as fi:
earlier in the code.
P.P.P.S. People were asking for an MCVE, so I hope this counts:
with open("usernames.txt", "a+")as fi:#opens usernames file as "fi" and closes once finished
with open("userinfos.txt", "a+") as f:#opens userinfos file as "f" and closes once finished
with open("quizzes.txt", "a+") as fil:
listofinfos = ["surname", "yeargroup"]#list with information apart from name and age
if True:#will always run
name = input("Enter your name:")
age = input("Enter your age:")
username = name[:3]+age#shortens name variable to first 3 letters and concatenates with age
if str(username) in fi.read():
hasAccount = True
print("found username")
else:
hasAccount = False
print("notfound")