class C: vs class C(object):

James Stroud jstroud at mbi.ucla.edu
Fri Jul 20 00:47:27 CEST 2007


Aahz wrote:
> In article <pan.2007.07.19.08.09.59.261957 at REMOVE.THIS.cybersource.com.au>,
> Steven D'Aprano  <steve at REMOVE.THIS.cybersource.com.au> wrote:
> 
>>It isn't wrong to use the old style, but it is deprecated, [...]
> 
> 
> Really?  Can you point to some official documentation for this?  AFAIK,
> new-style classes still have not been integrated into the standard
> documentation.  Maybe I missed something, though.
> 
> Note very carefully that "going away eventually" is *not* the same as
> deprecation.

How about "broke" instead of "deprecated":


 >>> class Old:
...   def __init__(self):
...     self._value = 'broke'
...   value = property(lambda self: self._value)
...
 >>>
 >>> class New(object):
...   def __init__(self):
...     self._value = 'works'
...   value = property(lambda self: self._value)
...
 >>> broke = Old()
 >>> broke.value
'broke'
 >>> broke.value = 'still broke'
 >>> broke.value
'still broke'
 >>>
 >>> works = New()
 >>> works.value
'works'
 >>> works.value = 'expected result of assignment here'
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AttributeError: can't set attribute


James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list