0

I am trying to run an other file in the same folder, by using a variable as the name of the file. But it always tells me, that its invalid.

name = File

import name

What do i have to add, that it detects, that this is a variable?

j1-lee
  • 13,764
  • 3
  • 14
  • 26
  • 1
    Does this answer your question? [importing a module when the module name is in a variable](https://stackoverflow.com/questions/13598035/importing-a-module-when-the-module-name-is-in-a-variable) – j1-lee Apr 10 '22 at 00:49

1 Answers1

0

If your file is a py file and the file in the same directory. Just import file

or if it is in subdirectory import folder.file

or if you just want to import a variable or a function from file import some_variable or from folder.file import some_variable

or import everything from file import *

If your file not a py file you have to open the file according to file type. You can not use import

sametatila
  • 56
  • 3