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


Groups > comp.lang.python > #85448

Re: Varable parsing error with python

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'else:': 0.03; 'assignment': 0.07; 'paths': 0.07; 'function,': 0.09; 'get.': 0.09; 'happen,': 0.09; 'logic': 0.09; 'referenced': 0.09; 'subject:parsing': 0.09; 'whatever.': 0.09; 'python': 0.11; 'def': 0.12; '6:30': 0.16; 'both,': 0.16; 'list):': 0.16; 'none.': 0.16; 'such,': 0.16; 'subject:python': 0.16; 'exception': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'variable': 0.18; 'skip:f 30': 0.19; 'feb': 0.22; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'errors.': 0.24; 'skip:i 40': 0.24; 'second': 0.26; 'post': 0.26; 'least': 0.26; 'skip:_ 20': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'fixed': 0.29; 'am,': 0.29; "doesn't": 0.30; 'statement': 0.30; 'code': 0.31; 'getting': 0.31; "skip:' 10": 0.31; 'branches': 0.31; 'such.': 0.31; 'another': 0.32; 'level.': 0.33; 'subject:with': 0.35; 'one,': 0.35; 'there': 0.35; 'skip:f 40': 0.36; 'error.': 0.37; 'example,': 0.37; 'two': 0.37; 'version,': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'tell': 0.60; 'new': 0.61; 'first': 0.61; "you'll": 0.62; 'places': 0.64; 'charset:windows-1252': 0.65; 'received:74.208': 0.68; '2015': 0.84
Date Tue, 10 Feb 2015 09:37:57 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Varable parsing error with python
References <CAFo8oMD+JZPuw3WedDOPDUo1+M+Qh-08rd57SfZneFFAG7u4mQ@mail.gmail.com> <CAPTjJmrPw56ZyEtnaXoDKCLCfGJ91AtwZTfifuBzw6kzHqmNmQ@mail.gmail.com> <CAFo8oMCMgwofgfv4Rq-anfNd9eV7bedJjjngYbF6-ANDkri17w@mail.gmail.com>
In-Reply-To <CAFo8oMCMgwofgfv4Rq-anfNd9eV7bedJjjngYbF6-ANDkri17w@mail.gmail.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:nIClBTIngZP3pLmXxSjBCc5K7VQx6HENitEiJMQqLTZ buxwtmmebvY5EMLw0kDDP78rkbwtXHae/6x3jCDIr0oCcV/EQP TU/y0TWm/0M4JJ+RJ6TgISeUIBes7wbjFeJUmPB4vKQG7JSc7g a+KzDraWmZoJpE2q+5DT4mxcHAzPpaKJ7KC/QLljg95MquqROt 1HY4o5405XmMYQauhRgfM6NKwjgFkKFo0/9LXGJdC1Q9CfgnX1 zX53MItrEhFEDGiXzt0VoObh33m0N6m1GcZg2jDXRRjpZ7zwu4 YljX+/XPiTRacggGQJ+IUNDLLMKQaav2ohA/r+L8tfzvisNlHs NSYJoEvnRXaaotfX443M=
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.18611.1423579083.18130.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1423579083 news.xs4all.nl 2927 [2001:888:2000:d::a6]:59173
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:85448

Show key headers only | View raw


On 02/10/2015 03:29 AM, OmPs wrote:
> On 10 Feb 2015 13:12, "Chris Angelico" <rosuav@gmail.com> wrote:
>>
>> On Tue, Feb 10, 2015 at 6:30 PM, OmPs <torque.india@gmail.com> wrote:
>>>      def _getPackgeVersion(xmlfile, p):
>>>          package = str(p)
>>>          if isinstance(fpmdict["application"]["package"], list):
>>>              for i in fpmdict["application"]["package"]:
>>>                  if i["@name"] == p:
>>>                      _pkgVersion = i["version"]
>>>          else:
>>>              _pkgversion = fpmdict["application"]["package"]["version"]
>>>              return _pkgVersion
>>
>> One of your branches doesn't have a return statement in it, so Python
>> just returns None. You may want to unindent that return statement one
>> level.
>>
> Tried that as well getting the same error.

The code above has at least two errors.  Fix them both, post a new 
version, and tell us the error you now get.

First error is that there's no return statement for the case where the 
first if is true.  You might fix that by unindenting, or by adding 
another return somewhere, or whatever.

Second error, depending on how you fixed the first one, is that for some 
paths through the function, _pkgVersion isn't initialized.  So if those 
conditions happen, and if you fixed the first error, you'll get an 
exception like:

UnboundLocalError: local variable '_pkgVersion' referenced before assignment

There also may be logic errors.  For example, if there are multiple 
places where the if i["@name...   logic triggers, do you want the 
_pkgversion to be the first such, or the last such.  What do you want 
for a value if there no matches?




-- 
DaveA

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


Thread

Re: Varable parsing error with python Dave Angel <davea@davea.name> - 2015-02-10 09:37 -0500

csiph-web