python - Alternative to referencing variable before assignment -


import time   # define variables username = "username" password = "password" customer_info_file_path = "c:\\users\megam\pycharmprojects\general stuff\the square pie co\customer " \                           "information\{}.txt ".format(name)  username_entry = input("enter username\n>>") password_entry = input("enter password\n>>")  if username_entry != username or password_entry != password:     print("access denied\nyou have entered username or password incorrectly. please check password , "           "account name , try again.\n") else:     print("access granted")      choice_menu = input("\na) view list of customers\nb) add customer\nc) delete customer\nd) log out\n>>")      if choice_menu == "a":         customer_info = open(customer_info_file_path, 'a', )         file = open(customer_info_file_path, 'r')         output = file.read()           print(output)      elif choice_menu == "b":         name = input("enter name of customer\n>>")         address = input("enter address of customer\n>>")         phone_number = input("enter phone number of customer\n>>")         fav_pie = input("enter customer's favourite pie\n>>")          # write info txt file         customer_info = open(customer_info_file_path, 'a')         customer_info.write("name:{}\n".format(name))         customer_info.write("address:{}\n".format(address))         customer_info.write("phone number:{}\n".format(phone_number))         customer_info.write("favourite pie:{}\n".format(fav_pie))         customer_info.close()      elif choice_menu == "d":         print("logging out")         time.sleep(2)         exit() 

i trying have value of name variable in file name (lines 7-8) referencing before creating results in error: nameerror: name 'name' not defined.

how can have value of name variable in file name , avoid error?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -