I am writing a program in python that takes an input for a username, and gives that user a nickname or "new name" from words from a separate text file.
#This file takes a name input from the user, gives the user a new name, and then saves the username and #new name in a separate "companion" file.
import random
import NameGenCompanion as NGC
unloggedname=1
Dict = open('Dictionary.txt').read().splitlines()
line1 = random.choice(Dict)
line2 = random.choice(Dict)
clear1 = line1.replace("#", "")
clear2 = line2.replace("#","")
word1 = clear1.replace("%","")
word2 = clear2.replace("%","")
newname = word1 + "-" + word2
username = input("What is your name? ")
Lo = open("NameGenCompanion.py").read()
if username in Lo:
unloggedname=0
print()#whatever the username variable was assigned in the companion file
if unloggedname!=0:
Log = open('NameGenCompanion.py','a')
Log.write("\n" + username + ' = ' + "'" + newname + "'")
Log.close()
print(username + "'s new name is " + newname)
The program saves the username and nickname to a "companion file".
Example: If my name is "John" and my given nickname is "Appleseed" then my program writes this to the companion file:
John = 'Appleseed'
Then, if I return to the program, and give it the same username, I want it to find variable John in the companion file, and assign the value of that variable to newname in the original file.
The issue is that I don't know how to make my program find username in the companion file, and then use that variable in the original file. How do I import and use any given variable in NameGenCompanion whose name is the same as username in the original file?