From: Chris Rebert on 4 Jun 2010 08:51 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 4 Jun 2010 13:49 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 4 Jun 2010 15:31 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
|
Pages: 1 Prev: Missing DLL in win98 Next: Wing IDE 3.2.8 released: Adds Python 2.7 support |