I'm writing a script that contains a large list. I'm trying to modify my script so that instead of needing to edit the script directly to add/remove items to this list, it reads lines from a text file. Is it possible to use variables inside of this data file?
For example, If my text file contains this:
thing
number+str(variable)
And my script looks like this:
import os
variable = '123456'
file = 'C:\whatever.txt'
#make the list 'commands'
with open(file) as f:
commands = []
for line in f:
line = line.replace('\n','')
commands.append(line)
#make the list 'oldcommands'
oldcommands = ['thing','number'+str(variable)]
print(commands)
print(oldcommands)
How do I get both of these outputs to be the same?
This is the result of running the script above:
['thing', 'number+str(variable)']
['thing', 'number123456']
Formatting the file in a particular way is not a problem, I'm just trying to make my script more modular/portable