Re: Referencing vars, methods and classes by name



En Thu, 08 Feb 2007 05:29:23 -0300, Paul Rubin <"http://phr.cx"@NOSPAM.invalid> escribió:

"Sagari" <boyandin@xxxxxxxxx> writes:
$a = ''b';
$obj->$a(); // call method b() of the instance $obj

What is the Python way of performing the same indirections?

For your last example we could say

obj.getattr(a)()

but even that is a bit ugly, depending.

Surely you meant to say getattr(obj, a)()

--
Gabriel Genellina

.



Relevant Pages

  • Re: do all primary keys use autonumber
    ... I agree with most of this, but suggest that one should be a bit cautious, depending on individual circumstances. ... I normally try to avoid using a multiple-field primary key, merely because I think it would be a nuisance to maintain all those fields (as parts of a foreign key) in the other Tables that refer to the current Table. ... Microsoft suggests avoiding linkages requiring more than about half a dozen indirections -- this is kind of a rule of thumb, I suppose, but it seems like good advice. ... My own preference is to lay on the indirect linkages pretty heavily early in the design stages, when I want to be sure that redundant data are kept to a minimum. ...
    (microsoft.public.access.tablesdbdesign)
  • Re: =?utf-8?B?562U5aSNOiBob3cgdG8gcmVtb3ZlIFxuIGluIHRoZSBsaXN0?=
    ... Yours reasigns a new list to the old name; the *contents* are the same as the former version, but now the name "lines" refers to a different list. ... Depending on the context, the difference may be important or not. ... Gabriel Genellina ...
    (comp.lang.python)