My first Python program
python at mrabarnett.plus.com
Wed Oct 13 19:49:09 CEST 2010
On 13/10/2010 18:17, Chris Rebert wrote:
> On Wed, Oct 13, 2010 at 9:56 AM, Seebs<usenet-nospam at seebs.net> wrote:
>> On 2010-10-12, MRAB<python at mrabarnett.plus.com> 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
The re.search and so forth return Match objects or None.
More information about the Python-list