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