Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85448
| Date | 2015-02-10 09:37 -0500 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18611.1423579083.18130.python-list@python.org> (permalink) |
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
Re: Varable parsing error with python Dave Angel <davea@davea.name> - 2015-02-10 09:37 -0500
csiph-web