0
import os.path

def start():
    if os.path.exists("new.txt") == False:
        Account = input('Username: ')
        Password_for_account = input('Password: ')
        all_the_content = []
        all_the_content.append(Account)
        all_the_content.append(Password_for_account)
        
    else:
        with open("new.txt") as file:
            content = file.read()
        all_the_content = content.strip('][').split(', ')

        while True:
            User = input('Username: ')
            Password = input('Password: ')
            if (User, Password) == all_the_content[0,1] :
                print('Done')
                break
            else:
                print('Invalid Password')
                continue
        return 'You have been succesfully logged in!'
print(start())
with open("new.txt") as file:
    content = file.read()
all_the_content = content.strip('][').split(', ')
def add_new_pass():
    new_username = input('Enter the new username: ')
    new_password = input('Enter the new password: ')
    all_the_content.append(new_username)
    all_the_content.append(new_password)
    return 'Your password has been added'
    
def check_pass(username):
    position = all_the_content.index(username)
    if username in all_the_content and position%2 == 0:
        return 'The password for '+ username, 'is '+ all_the_content[position + 1]
    else:
        return 'Invalid username'
print(add_new_pass())
a = input()
print(check_pass(a))
with open ('new.txt', 'w') as file:
    file.write(str(all_the_content))

I am a beginner. This code does everything as expected except one thing, every time I make thefile as "new.txt". Any help is appreciated! it stores it as "new2.txt". I am using Jupyter notebook.

  • Seems fine, all opens are done with `new.txt` as filename. Seems like something underlying is responsible for this behavior. – tripulse Oct 08 '20 at 04:08

2 Answers2

0

You already have a new.txt in that folder that's why it names this one new2.txt, erase or rename the first one and try to run you program agian.

BeeFriedman
  • 1,800
  • 1
  • 11
  • 29
0

Either you are not looking in the correct directory or the directory already has an existing file by the same name. Also check your write access to the directory

Aaj Kaal
  • 1,205
  • 1
  • 9
  • 8