I'm trying to get my code to check if a word is already in the document. However when choosing a variable (username)
that happens to share the same letters going to the right as the preexisting one in the file, it thinks that the name is taken. For example, if abcdefg
was in the file, if I was to right defg
or fg
or g
, it would think the username was taken.
def register():
print("━━━━ACCOUNT CREATION━━━━")
username = input("Create Username: ")
with open("Login.txt", "r") as loginfile:
if (username+",") in loginfile.read():
print("Sorry, but that username is taken.")
choice = input("Try again with a new name? (Y/N)")
choice = choice.upper()
My case: Say I had the name, Joe which is already in the file. If I tried to make a username that is just e, then it would think it is Joe, as it is looking for the e, next to a comma.
Anyway to fix this? Thanks!