For loop

Gordon McMillan gmcm at
Wed Mar 15 15:51:38 CET 2000

Boris Ottlewski wrote:
> I got this code snipet: (See the colons!)
> for a in i.something():
>      for cf in a.somethingelse():
>           print
> It works in python.exe (shell). How do I use this in embedded python? When a
> build a string with this code and do a Py_RunSimpleString() it raises a
> syntax error. Is there an alternative syntax? Is the colon someting just
> known to the python shell?

Make sure the lines are delimited properly, and the parser can 
detect a dendent and end-of-file:

"for i in a:\n for j in b: \n  something\n\n\0"

- Gordon

More information about the Python-list mailing list