Marcus Low wrote:
It's a Python scoping rule:
If a variable is assigned to anywhere within a function,
it is assumed to be local *everywhere* within that function.
See the faq for more:
Gary Herron
Opps here is the mail again, incase my formatting is lost, can someone
explain to me why this code behaves differently when "lister" and
"self.liste r" is swap remarked.
>
>
class abc :
# remark this later and unremark "self.liste r"
lister = []
def __init__ (self, val):
#self.lister = []
self.lister.app end(val)
globallist = []
>
def test () :
>
global l
for x in range(10) :
o = abc(x) globallist.appe nd(o) o
= ""
for i in globallist :
print i.lister
test()
>
--
http://mail.python.org/mailman/listinfo/python-list
explain to me why this code behaves differently when "lister" and
"self.liste r" is swap remarked.
>
>
class abc :
# remark this later and unremark "self.liste r"
lister = []
def __init__ (self, val):
#self.lister = []
self.lister.app end(val)
globallist = []
>
def test () :
>
global l
for x in range(10) :
o = abc(x) globallist.appe nd(o) o
= ""
for i in globallist :
print i.lister
test()
>
--
http://mail.python.org/mailman/listinfo/python-list
If a variable is assigned to anywhere within a function,
it is assumed to be local *everywhere* within that function.
See the faq for more:
Gary Herron