I'm trying to run a script that: 1. parses an xml file, that contains an arbitary id (say xml001) 2. generates a new module (say xml001.py) 3. imports the generated module and evaluate a function contained within it.
As I don't know the generated module name in advance, I'm not sure how I can import it!
This code does not work....
modulefile = something + ruleid + '.py'
writer = open(modulefile,'wb')
writer.write(code and sh1t)
....
....
modulename = replace(modulefile,'.py','')
eval('import %s as gc'%modulename)
# import ruleid as gc
result = gc.evaluateRule(thing)
Gets an error message of
Traceback (most recent call last):
File "C:\Stuff\roughwork4.py", line 152, in <module>
eval('import %s as gc'%modulename)
File "<string>", line 1
import booleanExpressionA12345 as gc
^
SyntaxError: invalid syntax
Nor this where I've replaced the eval()
bit (taken from here)...
modulename = open(modulefile)
gc = importCode(modulename,'gc')
Error message:
Traceback (most recent call last):
File "C:\Stuff\roughwork4.py", line 161, in <module>
result = gc.evaluateRule(rowvalueslist)
AttributeError: 'module' object has no attribute 'evaluateRule'
I appreciate any help! ps running on windows7, using eclipse ide....