By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

accessing object attribute as parameter

P: n/a
Hello,

I would like to access object parameter / variable from a function.

For example :
class A:
def __init__(self, x,y):
self.x = x
self.y = y

in the main program, I have a list of obj A:
L = [A(1,2), A(2,3)]

Now I need to access the value of x or y from a function:
def GetSomething(seqObj, ?):
return [obj.? from seqObj]
How can I access x or y through this function ?

Thanks,
Pujo

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
aj****@gmail.com wrote:
Hello,

I would like to access object parameter / variable from a function.

For example :
class A:
def __init__(self, x,y):
self.x = x
self.y = y

in the main program, I have a list of obj A:
L = [A(1,2), A(2,3)]

Now I need to access the value of x or y from a function:
def GetSomething(seqObj, ?):
return [obj.? from seqObj]
How can I access x or y through this function ?


Use getattr:

def GetSomething(seqObj, name):
return [getattr(obj, name) for obj in seqObj]
Diez

Jul 19 '05 #2

P: n/a
thanks Diez

pujo

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.