Beginner's scoping question

Farshid Lashkari lashkariNO at SPAMworldviz.com
Wed Nov 10 21:55:37 CET 2004


Hi,

You need to declare "a" as global before when you assign something to it
inside a function.

def __init__(self):
    global a
    a = 2

-Farshid

"Alan Little" <contact at alanlittle.org> wrote in message
news:4ef0f3a4.0411101240.21132006 at posting.google.com...
> a=1
> b=[]
> class C():
>    def __init__(self):
>       a=2
>       b.append(3)
>
> c = C()
>
> print b
> # [3]
>
> # but ...
> print a
> # 1
>
> ???





More information about the Python-list mailing list