local variable referenced before assignment

A.T.Hofkamp hat at se-162.se.wtb.tue.nl
Thu Oct 25 09:12:01 EDT 2007


On 2007-10-25, Tim Williams <tdwdotnet at gmail.com> wrote:
> On 25/10/2007, A.T.Hofkamp <hat at se-162.se.wtb.tue.nl> wrote:
>> On 2007-10-25, Pete Bartonly <none at try.invalid> wrote:
>> >
>> Also, brackets around conditions (in the if) are not needed, and comparing
>> against None is usually done with 'is' or 'is not' instead of '==' or '!='.
>> The result is then
>>
>> if logMsg is not None:
>
> Or just
>
>>>>  if logMsg:
>             do_something()
>
>:)

That is not the same.

If logMsg is 0, False, or empty string, the second variant
would be False and not True.

Albert



More information about the Python-list mailing list