Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85432 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2015-02-10 18:39 +1100 |
| Last post | 2015-02-10 15:40 -0500 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Varable parsing error with python Chris Angelico <rosuav@gmail.com> - 2015-02-10 18:39 +1100
Re: Varable parsing error with python Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-10 18:24 +0000
Re: Varable parsing error with python Dave Angel <davea@davea.name> - 2015-02-10 15:40 -0500
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-02-10 18:39 +1100 |
| Subject | Re: Varable parsing error with python |
| Message-ID | <mailman.18599.1423553990.18130.python-list@python.org> |
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. ChrisA
[toc] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-02-10 18:24 +0000 |
| Message-ID | <mbdid6$1i2$3@dont-email.me> |
| In reply to | #85432 |
On Tue, 10 Feb 2015 18:39:42 +1100, Chris Angelico 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. Even if he unindents the return, it will still return None if it doesn't find an i such that i["@name"] == p, as _pkgVersion only gets set if such a match is found. Could this be cause by eg a string case match issue? Perhaps: if i["@name"].lower() == p.lower(): would be a better comparison to use? -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2015-02-10 15:40 -0500 |
| Message-ID | <mailman.18623.1423600858.18130.python-list@python.org> |
| In reply to | #85460 |
On 02/10/2015 01:24 PM, Denis McMahon wrote: > On Tue, 10 Feb 2015 18:39:42 +1100, Chris Angelico 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. > > Even if he unindents the return, it will still return None if it doesn't > find an i such that i["@name"] == p, as _pkgVersion only gets set if such > a match is found. But if _pkgVersion weren't set, he'd be getting UnboundLocalError exception, not a None value. > -- DaveA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web