So, I'm making a program (hopefully) that is an 'improved' command prompt.
In my program, I want it to get all lines from a text file.
The text file will contain lines that look like this:
desktop=C:\Users\%username%\Desktop
scripts=D:\Scripts
What I want my program to do, is to read through that, and create new variables such as:
desktop = "C:\Users\%username%\Desktop"
scripts = "D:\Scripts"
I know there are probably better and safer ways to do this, but for now, I'd like to do it this way. Here is my code so far (it doesn't work):
with open("custom_shortcuts.txt","r") as f:
customShortcuts = [x.strip('\n') for x in f.readlines()]
for i in customShortcuts:
parts = i.split("=")
varName = str(parts[0])
varValue = str(parts[1])
eval("varName = varValue")
As you can see, I tried to use eval(), and failed.