A newbie question about class
joshm at taconic.net
Sun Feb 10 22:20:06 CET 2002
> > Could you explain a little more why "is not" is better than "!="?
> The short answer is that I don't think comparing something to None by
> identity will ever raise an error. Comparing it by magnitude might.
> Python allows you to override magnitude comparison methods: ==, !=, <, >,
> <=, >=. If you are using code written by somebody else, you don't know
> whether they've accounted for comparison to None in their comparison
> methods. If you compare to None by identity, you bypass that whole issue
> because comparison by identity ("is" and "is not") happens via id() and
> that's not something you can override (as far as I know).
And yet, unless you do use things like "!= None", bugs in packages like
FixedPoint would propogate. It's a double edged sword. Being able to use
"is not None" is a good way to be able to work around a bug like this (if
you don't have access to the source, for example), but I would hesitate to
say that it is "better".
# Joshua Muskovitz
# joshm at taconic.net
def lyyrs(sig): return '-'.join(sig.split()+["ly y'rs"])
lyyrs('Hire me! I need the work!')
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
More information about the Python-list