str(None) == '' ?

Ken Seehof 12klat at sightreader.com
Thu Jun 1 19:50:04 EDT 2000


Eduard Hiti wrote:

> I would like to suggest that
>
>     str(None)
>
> should NOT return the string 'None', since most of the time, it complicates
> things.
> ...

In python (unlike C), the syntax and semantics are usually designed to simplify
the debugging process as the highest priority.  The None value generally
represents a special case.  It is usually a bad idea to -implicitly- handle
special cases invisibly; in fact, it's better if the special cases make lots of
noise until the programmer pays attention :-)  On the other hand, it is often a
good idea to -explicitly- hide special cases.

For the same reason, python throws exceptions in many situations where an error
return value such as None could be used instead.  This is another way python
makes the programmer pay attention to special cases.  Somebody once suggested
that open() should return None if the file is not found (that way you could say

(warning: hypothetical pseudo-python with a Bad Idea (TM))

if open('myfile')
   ...

Yuck!

- Ken Seehof

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20000601/f00aac76/attachment.html>


More information about the Python-list mailing list