"Brunick, Gerard:(Constellation)" <gerard.brun...@constellation.com>:

> class Test(object):
>     x = 10
>
>     def __init__(self):
>         self.y = x
>
> t = Test()
> ---
>
> raises
>
> NameError: global name 'x' is not defined.

In the snippet, x is neither local to __init__() nor global to the
module. It is in the class scope. You can refer to it in one of two
ways:

   Test.x

or:

   self.x


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to