From: Chris Rebert on
On Fri, Jun 4, 2010 at 4:32 AM, macm <moura.mario(a)gmail.com> wrote:
> Hi Folks
>
> def myDef(x)
>        doSomething x
>        result = x.????
>        return coolThings
> ---------------------------------
>
> WhatYourName = ('python','is','cool')
>
> myDef(WhatYourName)
>
> so what I am looking for in myDef
>
>        result = WhatYourName
>
> ----------------------------------
> again :
> IhaveOtherName = ('some','thing')
>
> myDef(IhaveOtherName)
>
> so what I am looking for in myDef
>
>        result = IhaveOtherName
>
> ----------------------------------
>
> Is it possible with python?

Not without very evil black-magic hackery. Explain /why/ you want this
magic myDef() and someone will probably be able to suggest a better,
alternative approach.

Cheers,
Chris
--
http://blog.rebertia.com
From: Terry Reedy on
On 6/4/2010 7:32 AM, macm wrote:

A few types of objects have definition names (.__name__ attribute). All
have 0 to many namespace names. If you want to pass an attribute name,
pass it -- as a string.

> def myDef(x)
> doSomething x
> result = x.????
> return coolThings

def f(x. x_attr_name):
...
res = getattr(x, x__attr_name)
...

Terry Jan Reedy

From: jyoung79 on
Would vars() help? Check out this link:

http://www.daniweb.com/forums/thread134555.html

Jay

--

> def myDef(x)
> doSomething x
> result = x.????
> return coolThings
> ---------------------------------
>
> WhatYourName = ('python','is','cool')
>
> myDef(WhatYourName)
>
> so what I am looking for in myDef
>
> result = WhatYourName