scope question

Markus Schaber markus at schabi.de
Sun Aug 12 14:14:21 EDT 2001


Hi,

Vineet <vidog112 at YAHOO.COM> schrub:

> The reason you get an error like that, is because 'count' can only be
> read, not changed. In your first example, you are only referencing
> 'count'
> and therefore, no exception.  However, in your second example, you are
> attempting to write to a global variable from a local function, which
> is not allowed.

It is allowed.

But per default, all Variables that you assign a value are treated 
local. Global variables have to be explicitly "imported" by using the 
command "global variablename" in your function body before your first 
access.

-- 
1) Customers cause problems.
2) Marketing is trying to create more customers.
Therefore:
3) Marketing is evil.  (Grand Edwards in comp.lang.python)



More information about the Python-list mailing list