compile / exec
eric wilson
ewilson at nospam.jamdat.com
Wed Mar 14 18:57:38 EST 2001
hi -
i am new to python and i'm trying to use the compile / exec feature for
speeding up a loop. i'm using python v2.0 with pythonwin. i don't
understand why this doesn't work....
thanks in advance for the help.
//eric
the code snippet looks like this:
exec_code = compile("""
for eachLine in map(strip, allLines):
mySequence = split('\s\s+|\t', eachLine)
foundFields = str(gm2local(DateTimeFromString(mySequence[0])))[:-3]
+ '\t' + mySequence[1]+ '\t' + mySequence[4]+ '\t' + mySequence[5]+ '\t' +
mySequence[9]+ '\t' + mySequence[16] + '\n'
fw.write(foundFields)
count = count + 1
""", '', 'exec')
exec exec_code
the error message that i get when this piece of code runs is:
Traceback (most recent call last):
File "C:\Python20\Pythonwin\pywin\framework\scriptutils.py", line 301, in
RunScript
exec codeObject in __main__.__dict__
File "E:\W2\pytest\logman.py", line 114, in ?
checkArgs()
File "E:\W2\pytest\logman.py", line 110, in checkArgs
parmFind(sys.argv[1], sys.argv[2])
File "E:\W2\pytest\logman.py", line 55, in parmFindRAM
exec_code = compile("""
File "<string>", line 2
for eachLine in map(strip, allLines):
^
SyntaxError: invalid syntax
More information about the Python-list
mailing list