Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.12; '"global"': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:???': 0.16; 'value=none):': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'written': 0.21; 'saying': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'decide': 0.24; 'pass': 0.26; 'skip:" 20': 0.27; 'header:X -Complaints-To:1': 0.27; 'function': 0.29; 'code': 0.31; 'node': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'anywhere': 0.35; 'accessing': 0.36; 'method': 0.36; 'throughout': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'unable': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'skip:n 30': 0.60; 'email addr:gmail.com': 0.63; 'name': 0.63; 'skip:n 10': 0.64; 'self.value': 0.84; 'subject:..': 0.84; 'treats': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Scope of a class..help??? Date: Thu, 23 May 2013 12:18:16 +0200 Organization: None References: <913d7fc1-4608-4ff5-8b51-2ae2cd67781a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084aeca.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369304287 news.xs4all.nl 15965 [2001:888:2000:d::a6]:43902 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45791 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"