Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

New users can't create an account with part of an already existing username (text file problem)

I’m relatively new to python and am trying to create a reliable account creation and storage program. When the user wants to create a new username, the username_storage file is read to see if it already exists for another account.

# Enter and check username
            new_user = input("Username: ")
            if new_user in username_storage:
                print("Sorry, that username is already taken.\n")
            else:
                break

The problem is that whenever the user tries to create a new account using part of an existing username, the program does not allow it because it registers that the new username is inside a pre-made username.

e.g. if "william" is an existing username in the username_storage text file, it doesn’t allow the new username "will" or "liam" because those names are inside "william".

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks to anyone who may be able to answer this question; if I haven’t explained my problem clearly enough, please let me know!

>Solution :

usernames = username_storage.split()
print(new_user in usernames)

would do what you want assuming you cant have spaces in the username

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading