My first Python program

Chris Rebert clp2 at
Wed Oct 13 19:17:32 CEST 2010

On Wed, Oct 13, 2010 at 9:56 AM, Seebs <usenet-nospam at> wrote:
> On 2010-10-12, MRAB <python at> wrote:
>> Line 51
>> The __init__ method should always return None. There's no need to be
>> explicit about it, just use a plain "return".
> The real issue here is that I was assuming that open('nonexistent') returned
> None rather than raising an exception.

For future reference, the significant majority of things in Python
raise exceptions upon encountering errors rather than returning error
values of some sort.
Aside from APIs which explicitly provide a parameter to be returned as
a default value in case of error (e.g. getattr(obj, name, default)),
the only common exception* I can come up with off the top of my head
is str.find()**, and even that has an exception-throwing cousin,

*No pun intended; I just didn't want to have to break out a thesaurus.
**Returns -1 rather than raising ValueError

More information about the Python-list mailing list