loop scope

Mel Wilson mwilson at the-wire.com
Fri Mar 12 10:17:20 EST 2004


In article <kdg3505p3qj8t385htgcr88gkr3jceej98 at 4ax.com>,
Arthur <ajsiegel at optonline.com> wrote:
>On Thu, 11 Mar 2004 17:54:56 -0700, David MacQuigg <dmq at gain.com>
>wrote:
>>Scopes are defined by the boundaries of functions, classes and
>>modules, not for loops.  This is essential, or you would have to
>>declare global variables inside most for loops.
>
>I am not following this argument.  The surprise, specifically,  is
>that I don't think of myself as having declared "t" as a variable.  it
>is don't magically, as a placeholder and for a very specific purpose.
>So I would expect it to go away outside of the " [ " and " ] " by
>equal and opposite magic.

   Well, you don't declare variables in Python.  You use
names to refer to objects.  Python 2.4 may give each list
comprehension its own namespace, but for now names used in a
list comp. are used just as they would be in any other
statement.

        Regards.        Mel.



More information about the Python-list mailing list