I am receiving a string as an input, and that will determine the file associated with the function needed.
i.e. If I receive "File1"
I want to use File1.function()
, if I receive "File2"
I want to use File2.function
.
Asked
Active
Viewed 81 times
0
-
Like, do you have a list of all the files alrady? – pm980 Feb 07 '20 at 21:19
-
or are you checking your entire computer, or will you create an entirely new file depending on the file input – pm980 Feb 07 '20 at 21:19
-
I already have a list of files – jm96 Feb 07 '20 at 21:26
-
oh if you have a list of files then it should be simple, you can just index the point of the list where that is and open the file and assign it to a variable. – pm980 Feb 07 '20 at 21:28
-
Generally speak you _don't_ need (or want) to create variables with names not known until runtime. See the related question [How do I create a variable number of variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables) – martineau Feb 07 '20 at 21:51
1 Answers
0
You may use the execfile()
or os.system()
but this is dangerous if the filename comes from an untrusted source. Do never do this in public internet!

Stefan
- 1,789
- 1
- 11
- 16