I have many python files all with the same variable names but different values. Something like this would be in one:
var_one = 'happy'
var_two = '2345'
var_three = '-24.24'
var_four = 'Chocolate'
I need to write a Python script that can read these files and when I ask for var_one
it returns happy
. If I ask for var_two
it returns 2345
and so on and so forth.
Right now I have a python two compliant toolbox that does this using something along the lines of:
for fname in myfile:
d = toolbox.datafile(fname)
my_mood = d['var_one']
number = d['var_two']
decimal = d['var_three']
candy = d['var_four']
And then printing my_mood
would print out happy
.
However, this toolbox is not python 3 compliant and I did not make it so I would like to know if there is an easy built in toolbox that can accomplish this task.
Thanks in advance
EDIT**
The importing method seems like it will be the most helpful for answering this question. The only problem that I have now with it is that I do not know how to import the files.
To explain further I am going to be parsing the command-line arguments and one of the arguments will be the location of said file that we want to import. What is the syntax to import that?
I have an args.file
that equals <home/myname/python/myfile.py>
So how would I import args.file
?