[IronPython] How do I test if a variable is defined?
tony.meyer at gmail.com
Thu Nov 6 10:48:28 CET 2008
>> If you're running some sort of checker (pylint, pychecker) over this,
>> you might get a warning about the "name" line not doing anything. To
>> avoid that, you'll sometimes see a variant like this:
>> unused = name
>> except NameError:
>> # variable 'name' is not defined.
> Except then PyLint will complain that 'unused' is unused, plus you code no
> longer accurately conveys its intent.
Well pychecker ignores variables called "unused" (and _, but that
clashes with the gettext usage). I figured pylint did too, but that
was only a guess. IMO this code does accurately convey its intent - I
have seen this idiom in a lot of Python code.
More information about the Ironpython-users