Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85448 > unrolled thread
| Started by | Dave Angel <davea@davea.name> |
|---|---|
| First post | 2015-02-10 09:37 -0500 |
| Last post | 2015-02-10 09:37 -0500 |
| Articles | 1 — 1 participant |
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 Dave Angel <davea@davea.name> - 2015-02-10 09:37 -0500
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2015-02-10 09:37 -0500 |
| Subject | Re: Varable parsing error with python |
| Message-ID | <mailman.18611.1423579083.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web