preventing creation of instance

Thomas Heller theller at python.net
Wed Jun 18 11:30:39 EDT 2003


Peter Hansen <peter at engcorp.com> writes:

> Mirko Koenig wrote:
>> 
>> On Wed, 18 Jun 2003 14:42:36 +0200, Peter Hansen wrote:
>> 
>> > Mirko Koenig wrote:
>> >> Is using __new__ a common way in programming python like the contructor
>> >> in c++ or is it seldom used ?
>> >
>> > Perhaps the best answer is that it's *extremely* "new", no pun intended.
>> > It was only just added to the language, and relatively few people have
>> > probably tried using it, let alone figured out how to judge the best
>> > time to use it, and when not to.
>> >
>> > And many of us are still programming with older versions that didn't
>> > have that feature.
>> 
>> So perhaps throwing an exception in __init__ is the better way for me?
>
> In my opinion, and certainly after seeing Aahz' comment, yes.

See also:

http://www.python.org/workshops/1997-10/proceedings/savikko.html

Thomas




More information about the Python-list mailing list