[python] pass the name of args

M

macm

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?

Regards

macm
 
C

Chris Rebert

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

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
 
T

Terry Reedy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top