Language Design: list_for scope?

guthrie guthrie at mum.edu
Fri Jul 21 12:37:46 EDT 2006


I'm pretty new to Python, and trying to parse the grammar.

Q: What is the scope of the testlist in a list_for?

For example;
Instead of;
      for x in [ x in dict if dict[x]=="thing" ]:
in this:
      for x in dict and dict[x]=="thing":
x is undefined.

And why doesn't this work:
	for x in dict if dict[x]=="thing":

Any insights/hints on why it is broken?

Thanks,
Gregory
----------------------------------------
http://docs.python.org/ref/grammar.txt:
list_for ::=
              "for" expression_list "in" testlist
               [list_iter]
testlist ::=
              test ( "," test )* [ "," ]
list_iter ::=
              list_for | list_if
list_if ::=
              "if" test [list_iter]


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----



More information about the Python-list mailing list