Varable parsing error with python

Denis McMahon denismfmcmahon at gmail.com
Tue Feb 10 13:24:38 EST 2015


On Tue, 10 Feb 2015 18:39:42 +1100, Chris Angelico wrote:

> On Tue, Feb 10, 2015 at 6:30 PM, OmPs <torque.india at 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 at gmail.com



More information about the Python-list mailing list