Re: Someone enlightened me

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Herron

    Re: Someone enlightened me

    Marcus Low wrote:
    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
    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:

    Contents: Programming FAQ- General questions- Is there a source code-level debugger with breakpoints and single-stepping?, Are there tools to help find bugs or perform static analysis?, How can I c...


    Gary Herron

Working...