I'm making a program where the user creates a username and then the program adds the username into a file, but for some reason I can't read the file.
usernames = open('usernames', 'r+')
def create_username():
while True:
username = str(input('create username: '))
if len(username) > 12 or len(username) < 3:
print('your username must be 3-12 characters long')
elif username in usernames:
print('the username is already in use')
elif len(username) <= 12:
usernames.write(username + '\n')
print('username created')
print('here\'s all the used usernames:',
usernames.read()) # i want this print function to print the whole file
usernames.close()
return username
create_username()
the content of the txt file looks like this:
afd
safds
asdfafsafsdafs
asfas
ok123
adsf
ffsda
afd
daf
fdsa
afsfas
dsaf
sadffas
dfasfdas
fdafsf
Ok so there is some other question that is similiar to this, but this one is unique because username in usernames
makes the file pointer go to the last row of the file and in the other one it's because of read()
.