If I use the exec
statement for a for
statement, an error occurs.
My code:
exec 'for i in A_'+aws_n+'_DATI[:]:'
exec ' a_'+aws_n+'_tt += {datetime.datetime.strptime(A_'+aws_n+'_DATI[n], "%Y%m%d%H%M")}'
exec ' n += 1'
Result:
**Traceback (most recent call last):
File "aws_merge.py", line 140, in <module>
exec 'for i in A_'+aws_n+'_DATI[:]:'
File "<string>", line 1
for i in A_156_DATI[:]:
^
SyntaxError: unexpected EOF while parsing**
However, in the above code, if you remove the exec
statement and manually process the variable aws_n
, it will run without any problems.
for i in A_156_DATI[:]:
print n
n += 1
Why is not it running?