Implementing class attribute access methods via pseudo-functi on o verloading.

Doran_Dermot at emc.com Doran_Dermot at emc.com
Mon Oct 25 07:47:12 EDT 2004


Hi Daniel,

The "return" statement will do just that!  Nothing gets executed after the
return and therefore the else is not required.  However, this does suggest
that this code is not clear to others!  That in itself is worth noting!

I agree that the manner in which I was trying to simulate "function
overloading" might also be unclear!

Thanks for the reaction.


-----Original Message-----
From: python-list-bounces+doran_dermot=emc.com at python.org
[mailto:python-list-bounces+doran_dermot=emc.com at python.org]On Behalf Of
Daniel Dittmar
Sent: 25 October 2004 12:13
To: python-list at python.org
Subject: Re: Implementing class attribute access methods via
pseudo-function o verloading.


Doran_Dermot at emc.com wrote:
>   def title( self, title=None ):
>     if title == None:
>       return self._title
>     self._title = title

You probably meant
   def title( self, title=None ):
     if title == None:
        return self._title
     else:
        self._title = title

or every read access would clear the attribute.

1. Some people dislike methods that do very different things depending 
on the parameters. These are difficult to explain. Though in your case, 
one central explanation and links from all the methods should be enough.

2. None is often a useful value, so perhaps you should use a module 
local variable like _GetValue (actual value is irrelevant)
     def title (self, title = _GetValue):

Daniel
-- 
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list