I am trying to import a lot of files. I have a list (myList) of strings that are the names of the modules files that I want to import. All the files I want to import are in a directory called parentDirectory. This directory is located in the folder in which this code is located.
What I still have:
myList = {'fileOne', 'fileTwo', 'fileThree'}
for toImport in myList:
moduleToImport = 'parentDirectory.'+toImport
import moduleToImport
This code simply considers moduleToImport as the name of the module, but I want the code to understand that it is a variable for the string.
This is the Error Code:
dule>
import moduleToImport
ImportError: No module named moduleToImport
source
share