[Tutor] dictionary dispatch for object instance attributes question

Liam Clarke cyresse at gmail.com
Sun Feb 20 10:59:17 CET 2005


Hi, 

just an expansion on Brian's query, is there a variant of getattr for
instance methods?

i.e. class DBRequest:
    def __init__(self, fields, action):
        self.get(fields)
    
    def get(self, fields):
        print fields


Instead of self.get in _init__, the value of action to call a
function? Or, is it going to have to be dictionary dispatch?

Regards, 

Liam Clarke

On Wed, 16 Feb 2005 16:49:21 -0500, Brian van den Broek
<bvande at po-box.mcgill.ca> wrote:
> Jeff Shannon said unto the world upon 2005-02-16 16:09:
> > On Tue, 15 Feb 2005 23:48:31 -0500, Brian van den Broek
> > <bvande at po-box.mcgill.ca> wrote:
> 
> <SNIP some of Jeff's responses to my evaluation of his earlier
> suggestions>
> 
> 
> > Yes, if you know that you will only have one header per line, then
> > it's reasonable to process them one line at a time.  You could
> > alternatively have the TP_file gather all the header lines for a given
> > node into a list, and then process that list to create the Node
> > instance, but given the specifics of your case you probably wouldn't
> > gain anything over your current approach by doing so.
> >
> > This is what makes programming so interesting -- there's so many
> > different choices possible, and which one is best depends on a large
> > number of factors.  When writing a program for some task, the best
> > design for a particular set of circumstances may be completely
> > different than the best design for a somewhat different particular set
> > of circumstances -- and the best design for general usage is probably
> > an altogether different thing still.
> >
> > Good luck!
> >
> > Jeff Shannon
> 
> Thanks Jeff,
> 
> the confirmation that my assessment made sense is very helpful. Due to
> the my lack of experience (as discussed in my response to Kent) I'm
> always uncomfortable rejecting a proposed solution -- is my assessment
> that the solution isn't the best a product of that inexperience, or am
> I on to something? So, thanks for taking the time to `bless' my
> assessment.
> 
> Best to all,
> 
> Brian vdB
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list