For loop

Gordon McMillan gmcm at hypernet.com
Wed Mar 15 09:51:38 EST 2000


Boris Ottlewski wrote:
> 
> I got this code snipet: (See the colons!)
> 
> for a in i.something():
>      for cf in a.somethingelse():
>           print cf.property
> 
> 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