ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
Re: [Tutor] New-style classes
by Jan Eden other posts by this author
Sep 29 2005 6:01AM messages near this date
Re: [Tutor] New-style classes | Re: [Tutor] New-style classes
Hi Kent,

Kent Johnson wrote on 29.09.2005:

> >Data.Base has no base classes, so it is not based on a built-in
> >type: How can it be a new-style class?
> 
> Data.Base is not a new-style class, but the classes in Show are. And
> properties may appear to work in old-style classes. This document
> http://www.python.org/2.2.3/descrintro.html#property says,
> Properties do not work for classic classes, but you don't get a
> clear error when you try this. Your get method will be called, so it
> appears to work, but upon attribute assignment, a classic class
> instance will simply set the value in its __dict__ without calling
> the property's set method, and after that, the property's get method
> won't be called either.

Thanks for your quick reply. I read the document you mentioned before, that's why I was conf
used.

My actual code looks like this:

class Base:
    def GetOwnType(self):
        try: return self._own_type
        except: return self.child_type
    
    def SetOwnType(self, value):
        self._own_type = value
        
    own_type = property(GetOwnType, SetOwnType)

For some of the subclasses of Base, the attribute own_type is defined, the others should use
 child_type.

For both groups of subclasses, this works fine - if own_type has not been set somewhere else
, self.child_type is returned when calling self.own_type.

When checking Data.Base.__mro__, I get an error, so it is not a new-style class by itself.

On the other hand, every time I use the own_type attribute, I do so via instances of new-sty
le classes (Show.Page, Show.Author etc).

Could it be that the nature of these classes makes the code in Data.Base behave according to
 the new-style rules?

Thanks,

Jan
-- 
I'd never join any club that would have the likes of me as a member. - Groucho Marx
_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Jan Eden
Kent Johnson
Jan Eden
Kent Johnson

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved