Re: Referencing vars, methods and classes by name

2007-02-09 Thread Terry Reedy
"Sagari" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Thanks to everyone for all the comments. I am migrating from PHP to | Python and I am looking for the means to port a controller code that | would, roughly speaking, call a certain method of a certain class | (both class and m

Re: Referencing vars, methods and classes by name

2007-02-09 Thread Sagari
> For your other examples there are gross hacks using the dictionaries > that represent the local and global symbol tables, so we translate > your examples fairly directly, but stylistically we'd usually stay > away from that kind of thing. Thanks to everyone for all the comments. I am migrating f

Re: Referencing vars, methods and classes by name

2007-02-08 Thread greg
Gabriel Genellina wrote: > On 8 feb, 05:51, Paul Rubin wrote: > > > "Gabriel Genellina" <[EMAIL PROTECTED]> writes: > > > > > Surely you meant to say getattr(obj, a)() > > > > Yeah, darn. Counterintuitive. > > A generic function helps on using it on objects of any kind

Re: Referencing vars, methods and classes by name

2007-02-08 Thread Gabriel Genellina
On 8 feb, 05:51, Paul Rubin wrote: > "Gabriel Genellina" <[EMAIL PROTECTED]> writes: > > >obj.getattr(a)() > > > but even that is a bit ugly, depending. > > Surely you meant to say getattr(obj, a)() > > Yeah, darn. Counterintuitive. I keep making that error in my ow

Re: Referencing vars, methods and classes by name

2007-02-08 Thread Paul Rubin
"Gabriel Genellina" <[EMAIL PROTECTED]> writes: > >obj.getattr(a)() > > but even that is a bit ugly, depending. > Surely you meant to say getattr(obj, a)() Yeah, darn. Counterintuitive. I keep making that error in my own code too. Maybe I should put in an RFE. -- http://mail.python.org/mai

Re: Referencing vars, methods and classes by name

2007-02-08 Thread Gabriel Genellina
En Thu, 08 Feb 2007 05:29:23 -0300, Paul Rubin <"http://phr.cx"@NOSPAM.invalid> escribió: > "Sagari" <[EMAIL PROTECTED]> 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 cou

Re: Referencing vars, methods and classes by name

2007-02-08 Thread Paul Rubin
"Sagari" <[EMAIL PROTECTED]> writes: > $a = 'b'; > $obj =& new $a(); // instantiating class b() Classes are first class objects in python: class b: . # define class b We could assign the class object to a variable a = b and make an instance: obj = a()# same as "obj = b()" Co

Re: Referencing vars, methods and classes by name

2007-02-08 Thread Paul Rubin
"Sagari" <[EMAIL PROTECTED]> writes: > $a = ''b'; > $$a = $something; // assign to $b > $$a($p1); // call function b($p1) > $obj->$a(); // call method b() of the instance $obj > > What is the Python way of performing the same indirections? We would not do that. We don't (usually) use the interpr

Re: Referencing vars, methods and classes by name

2007-02-08 Thread Sagari
Quite forgot to add the obvious example (in PHP): $a = 'b'; $obj =& new $a(); // instantiating class b() -- http://mail.python.org/mailman/listinfo/python-list