It's not clear what your purpose is or what you are trying to write. If you need help then we need more details. Tracebacks, original code, updated code, code you've tried... etc. Much more detail than you've provided. But in any case here is something very simple that I wrote in order to write look back on to remember how to write to files properly. This helped me come up with a registration form and many other ideas and is very basic... Hashing, dictionaries, checks for username/password matching using dictionary key/value pairs all plays into registration forms. If you are writing software that writes to a file for another file then you need to write it as a class or "module" that can be imported into that file. Also if you are writing to a file that does not exist yet and your program need to create it the use a try/except/else block to do that. You also don't need to use the 'r' parameter when opening to read, files are by default open to read if nothing is specified.
import json def get_stored_username(): filename = 'username.json' try: with open(filename) as f_obj: username = json.load(f_obj) except FileNotFoundError: return None else: return username def get_new_username(): username = input("What is your name? ") filename = 'username.json' with open(filename, 'w') as f_obj: json.dump(username, f_obj) return username def greet_user(): username = get_stored_username() if username: valid_username = input("Is " + username + " the correct username? (Y/N): ") if valid_username.lower() == 'n': username = get_new_username() print("We'll remember you when you come back, " + username + "!") else: print("Welcome back, " + username + "!") else: username = get_new_username() print("We'll remember you when you come back, " + username + "!") greet_user()