Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45791
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Scope of a class..help??? |
| Date | 2013-05-23 12:18 +0200 |
| Organization | None |
| References | <913d7fc1-4608-4ff5-8b51-2ae2cd67781a@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2006.1369304287.3114.python-list@python.org> (permalink) |
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??
>
>
> class Node:
> def __init__(self, value=None):
> self.value = value
> self.next = None
>
>
>
> def number_to_LinkedList(numbers):
> pass
> list_numbers = list(numbers)
> head_node = Node() #unable to create the instance saying
> UnboundedLocal head_node.value = list_numbers[0]
> head_node.next = None
> current_node = head_node
> for i in range(1,len(list_numbers)):
> new_node = Node()
> new_node.value = list_numbers[i]
> new_node.next = current_node
> current_node = new_node
> current_node.next = None
> while Node:
> print Node.data
> Node = Node.next
You have to decide if you want to use a name in a function locally or to
access a global. Python treats names that are being assigned to anywhere in
a function as local throughout the whole function.
x = "global"
def f():
print x # ok, access global variable
x = "global"
def g():
x = "local"
print x # ok, accessing local variable
x = "global"
def h():
print x # error, accessing local variable that has not
# been assigned a value
x = "local"
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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