Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'true,': 0.04; 'executed': 0.07; 'line:': 0.07; 'subject:Error': 0.07; 'referenced': 0.09; 'def': 0.10; "hasn't": 0.15; '0.0,': 0.16; '1000):': 0.16; 'dist': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'idx': 0.16; 'iteration,': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'wrote:': 0.17; 'variable': 0.20; 'skip:" 30': 0.20; 'assignment': 0.22; 'statement': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'looks': 0.26; '(most': 0.27; 'set.': 0.27; 'indentation': 0.29; 'preceding': 0.29; 'received:192.168.1.3': 0.29; 'subsequently': 0.29; 'points': 0.29; 'error': 0.30; 'code': 0.31; 'point': 0.31; 'file': 0.32; 'received:84': 0.32; 'print': 0.32; 'getting': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'wrong': 0.34; 'false': 0.35; 'continue': 0.35; "wasn't": 0.36; 'skip:p 20': 0.36; 'unable': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'end': 0.40; 'skip:u 10': 0.60; 'first': 0.61; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; "'while'": 0.84; 'reply-to:addr:python.org': 0.84; '74,': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=Bd1aI8R2 c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=1EKJ2blYo8kA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=05zpGK49tAp2GH5y-nMA:9 a=wPNLvfGTeEIA:10 a=hxpXsOvLE4qp_rQZ:21 a=17AJI3vnT9aPSUPR:21 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Wed, 14 Nov 2012 18:48:52 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Error References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 65 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352918938 news.xs4all.nl 6849 [2001:888:2000:d::a6]:42381 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33352 On 2012-11-14 15:18, inshu chauhan wrote: > > for this code m getting this error : > > CODE : > def ComputeClasses(data): > radius = .5 > points = [] > for cy in xrange(0, data.height): > for cx in xrange(0, data.width): > if data[cy,cx] != (0.0,0.0,0.0): > centre = data[cy, cx] > points.append(centre) > > Look at this line: > change = True > It's indented the same as the preceding 'if' statement, which means that it's executed even if the body of the 'if' statement wasn't executed and it hasn't assigned to 'centre'. So 'change' has been set to True, the 'while' loop is entered, and subsequently an attempt is made to get 'centre', which hasn't been set. > while change: > > for ring_number in xrange(1, 1000): > change = False > new_indices = GenerateRing(cx, cy, ring_number) > > > for idx in new_indices: > point = data[idx[0], idx[1]] > > if point == (0.0, 0.0, 0.0 ): > continue > else: > dist = distance(centre, point) > if dist < radius : > print point > points.append(point) > change = True > print change > > The indentation of this line looks wrong to me: > break > It'll affect the 'for cx' loop at the end of its first iteration, every time. > > ERROR : > Traceback (most recent call last): > File "Z:\modules\classification2.py", line 74, in > ComputeClasses(data) > File "Z:\modules\classification2.py", line 56, in ComputeClasses > dist = distance(centre, point) > UnboundLocalError: local variable 'centre' referenced before assignment > > And i am unable to understand .. WHY ? >