any ways to judge whether an object is initilized or not in a class

Steve Holden steve at holdenweb.com
Tue Mar 20 02:21:26 EDT 2007


Steven D'Aprano wrote:
> On Mon, 19 Mar 2007 19:48:37 +1100, Ben Finney wrote:
> 
>> It's also best to inherit every class from another class, leading to a
>> single hierarchy for all classes and types. 'object' is the one to
>> choose if you don't want the behaviour of any other class.
> 
> What's wrong with old-style classes?
> 
> On the plus side:
> 
> - Why inherit from something if you don't need to?
> 
> - Less typing.
> 
> - Attribute-lookup is much faster, perhaps as much as twice as fast.
> http://www.python.org/~jeremy/weblog/030506.html
> 
> - Documentation on old style classes is more extensive.
> 
> - You can't use new style classes for exceptions.
> 
In 2.5 exceptions are new-style objects, thanks to Brett Cannon's PyCon 
work from 2006:

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
Started with C:/Steve/.pythonrc
  >>> Exception
<class exceptions.Exception at 0x00964510>
  >>>


Python 2.5b2 (trunk:50713, Jul 19 2006, 16:04:09)
[GCC 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
Started with C:/Steve/.pythonrc
  >>> Exception
<type 'exceptions.Exception'>
  >>>

> 
> 
> On the minus side:
> 
> - Properties don't work as you expect them too.
> 
> - Slots don't work at all.
> 
> 
> In other words, the only reason why you HAVE to use a new style class is
> that you need properties or __slots__. You might WANT to use a new style
> class to inherit from built-in types. Otherwise, the choice between old
> and new is not very important.
> 
> 
> 
Most of the documentation on old-style classes, of course, applies to 
new-style classes too.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com




More information about the Python-list mailing list