How do I write to a python file using a command in another python file?

23 Views Asked by At

I am making a program that takes passwords and can make new ones. I want to be able to save passwords that I have made in one file as a part of a string in a list in a different file.

The list.append() method won't work because after I close the program and run it again, the list gets redefined with what was originally in it; ie, the predefined passwords I have written into the program. if it helps, here it helps.

passkey_has_been_made = True
number_of_times_that_someone_entered_the_wrong_key = 0

def sleep(secs: float) -> None: ...

def make_new_password():
    create_password = input("Create a new password: ")
    password = None
    if len(create_password) > 16:
        print("Password cannot be longer than 16 characters!")
    else:
        password = create_password
        key_list.append(str(password))

while passkey_has_been_made:
    action = input('what would you like to do?')
    if action == 'load new password':
        pass_key_check = input('enter an administrative password')
        if pass_key_check in file2.admin_passkey:
            make_new_password()
    elif action == 'log in':
        if number_of_times_that_someone_entered_the_wrong_key < 5:
            
            pass_key_check = input('enter your passkey\n')
            
            if pass_key_check in file2.key_list:
                    print("Access Granted.\n")
                    input("Press enter to continue.")
                    break
            else:
                number_of_times_that_someone_entered_the_wrong_key += 1
                print('invalid\n')
        else:
            print('to many attempts! System shutdown!')
            sleep(10)
            print('rebooting...')
            sleep(2)
            number_of_times_that_someone_entered_the_wrong_key = 0
#file2
key_list = ['password']
admin_passkey = [key_list[0]]
0

There are 0 best solutions below