namespace question
Piet van Oostrum
piet at cs.uu.nl
Wed Dec 13 06:10:41 EST 2006
>>>>> "jm.suresh at no.spam.gmail.com" <jm.suresh at gmail.com> (jssgc) wrote:
>jssgc> This one works. But I suppose there must be a way to artificially
>jssgc> create a new block of code, some thing like this,
>jssgc> class Test:
>jssgc> c = None
>jssgc> <<howToCreateANewNameSpace>>:
>jssgc> # Objects created here are local to this scope
>jssgc> a = 1
>jssgc> b = 2
>jssgc> global c
>jssgc> c = a + b
As you want c to be an *instance* variable, the normal idiom would be:
class Test:
def __init__(self):
a = 1
b = 2
self.c = a+b
x = Test()
print x.c
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list
mailing list