Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45790

Re: Scope of a class..help???

References <913d7fc1-4608-4ff5-8b51-2ae2cd67781a@googlegroups.com>
Date 2013-05-23 20:00 +1000
Subject Re: Scope of a class..help???
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2005.1369303610.3114.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, May 23, 2013 at 7:51 PM,  <lokeshkoppaka@gmail.com> wrote:
> i had written the following code i am unable to create the instance of the class "Node" in the method "number_to_LinkedList" can any one help me how to do ??
> and what is the error??

It would really help if you post the actual exception and traceback.
It's UnboundLocal, not Unbounded... and here's the problem:

> def number_to_LinkedList(numbers):
>       head_node = Node() #unable to create the instance saying UnboundedLocal
>       while Node:
>         print Node.data
>         Node = Node.next

You're assigning to Node. I think you mean to have some other local
variable here, for the iteration at the end. Since you assign to the
name Node inside the function (and don't have a global declaration),
the name Node is local to the function. Python doesn't let you
reference the global "prior to" shadowing it with the local, so you
get this error.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Scope of a class..help??? lokeshkoppaka@gmail.com - 2013-05-23 02:51 -0700
  Re: Scope of a class..help??? Chris Angelico <rosuav@gmail.com> - 2013-05-23 20:00 +1000
  Re: Scope of a class..help??? Peter Otten <__peter__@web.de> - 2013-05-23 12:18 +0200
  Re: Scope of a class..help??? lokeshkoppaka@gmail.com - 2013-05-23 03:23 -0700
    Re: Scope of a class..help??? Chris Angelico <rosuav@gmail.com> - 2013-05-23 20:27 +1000
  Re: Scope of a class..help??? lokeshkoppaka@gmail.com - 2013-05-23 03:25 -0700
    Re: Scope of a class..help??? Chris Angelico <rosuav@gmail.com> - 2013-05-23 21:40 +1000
    Re: Scope of a class..help??? Tim Roberts <timr@probo.com> - 2013-05-23 22:05 -0700

csiph-web