Creating a variable of a specific type

Aahz aahz at pythoncraft.com
Thu Feb 5 08:54:29 EST 2004


In article <bvtei9$10enm4$1 at ID-111250.news.uni-berlin.de>,
Diez B. Roggisch <nospam-deets at web.de> wrote:
>
>Now back to your problem: I don't know right from my head what socket
>requires as inet-type, but I guess its a tuple of some sort. You don't need
>to declare a variable for that - just use it. If you need to check for a
>symbol not beeing initialized, simply use None as value, like here:
>
>address = None
>if address:
>  do_something(address)
>
>None is considered false. You might be more explicit, by using
>
>if address == None:
>
>but thats a matter of taste (to me, at least...)

No, that's not a matter of taste, it's a matter of incorrect coding.
Using ``==`` calls a method on address, which could return true even if
address isn't None.  Much better to use ``is``, which is guaranteed to
return true only if address really *is* None.

Note that in the absence of special methods for comparison, all Python
objects are true, so your original formulation is especially appropriate.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death."  --GvR



More information about the Python-list mailing list