I'm trying to make an engine that takes the contents of a file that has python files and functions within them in a format as follows:
lib1 func1 func2 func3
lib2 func4
etc. I set up a test with two python files and three functions, but the code I am using to import the libraries and functions isn't working:
class engine (object):
def __init__ (self, sceneFile):
# gets contents of sceneFile, then closes
scenes = open (sceneFile, 'r')
lines = scenes.readlines ()
scenes.close ()
self.libs = []
# finds functions and libraries
for i in range (len (lines)):
lineContents = lines[i].split()
self.libs.append (importlib.import_module (lineContents[0])) # libraries in sceneFile
for j in range (len (lineContents) - 1):
self.libs[i].append (lineContents[j + 1]) # functions in sceneFile
def start (self, nextScene):
# finds function and library, imports
for i in range (len (self.libs)):
for j in range (len (self.libs[i])):
if self.libs[i][j] == nextScene:
nextScene = getattr (self.libs[i], self.libs[i][j])
self.start (nextScene)
When I try running this with the test programs, this error pops up:
Traceback (most recent call last):
File "ugsE.py", line 32, in <module>
Engine = engine ("ugsEtest.txt")
File "ugsE.py", line 21, in __init__
self.libs[i].append (lineContents[j + 1]) # functions in sceneFile
AttributeError: 'module' object has no attribute 'append'
What does this mean? I have a feeling that it's because I'm creating a list of modules, but shouldn't that work?
self.libs[i]is not a list so it has noappend()method.