[Pythonmac-SIG] parameterize dot notation

TattooMabonzoK. TattooMabonzoK.
Wed, 20 Sep 2000 11:54:02 +0200


Hi Chris,

On Tuesday, September 19, 2000, at 09:44 PM, Chris Barker wrote:

> "Tattoo Mabonzo K." wrote:=20
> > In UserLand's Frontier, paths to 'objects' are denoted using a =
syntax such as the=20
> following:=20
> > =20
> > root.foo.bar.fubar (1)=20
> > =20
> > Now suppose that v1, v2, v3 are variables holding the values 'foo', =
'bar', 'fubar'=20
> respectively, the following notation is equivalent to (1):=20
> > =20
> > root.[v1].[v2].[v3] (2)=20
> > =20
> > I was wondering if there's a way in Python to achieve the same ie =
'parameterize'(is that a=20
> correct word anyway?)=20
> =20
> I don't think so, but you can achieve the same thing with an eval=20
> statement:=20
> =20
> eval("root."+v1+"."+v2+"."v3)=20

I figured as much but that's oh sooooo ugly :-) hence pythonic at all...
Besides it's not really practical because I'll use that kind of code all =
over the place

> =20
> > After all, Python seems to support syntax such as=20
> > =20
> > root.foo().bar().fubar (meaning that the intermediate steps in the =
previous path are=20
> not taken 'literally' if you see what I mean).=20
> =20
> no, I don't. In that case, each step is taken literally. I'm pretty =
sure=20
> the only way that call would work is if: =20
> =20
> root has a member, "foo" which is a function that when called returns =
an=20
> object that has a member, "fubar". the value of the member "fubar" is=20=

> returned.=20

What I meant to say is that each step in the path is actually =
'evaluated' meaning that a we're not too far from each step being an =
'expression'.

Thanks for you input!

=3D tmk =3D

> =20
> =20
> -Chris=20
> =20
> -- =20
> Christopher Barker,=20
> Ph.D.                                                           =20
> cbarker@jps.net                      ---           ---           ---=20=

> http://www.jps.net/cbarker          -----@@       -----@@       =
-----@@=20
>                                    ------@@@     ------@@@     =
------@@@=20
> Water Resources Engineering       ------   @    ------   @   ------   =
@=20
> Coastal and Fluvial Hydrodynamics -------      ---------     --------  =
  =20
> =
------------------------------------------------------------------------=20=

> =
------------------------------------------------------------------------=20=

> =20
> =20