When I call print
from eval
:
def printList(myList):
maxDigits = len(str(len(myList)))
Format = '0{0}d'.format(maxDigits)
for i in myList:
eval('print "#{0:' + Format + '}".format(i+1), myList[i]')
it gives an error:
print "#{0:01d}".format(i+1), myList[i]
^
SyntaxError: invalid syntax
I tried to make use of this, and re-wrote it:
def printList(myList):
maxDigits = len(str(len(myList)))
Format = '0{0}d'.format(maxDigits)
for i in myList:
obj = compile(src, '', 'exec')
eval('print "#{0:' + Format + '}".format(i+1), myList[i]')
but this complains about the i
:
NameError: name 'i' is not defined
P.S. I'm dealing with python2.6