convert string literal to object attribute

B

BiraRai

def getAttributeForProperty(self,rollnumber,attribute):
# attribute have the value _ward
'''
If year is null then use current year.
Returns the value of the attribute for the given roll number
'''
print 'Searching for attribute', attribute
for index, i in enumerate(self._aa):
if (rollnumber == i._roll_number) and ( hasattr(i,attribute) ) :
print index,i.attribute (COMPILER ERROR HERE)
return i.attribute
return
print "\n"
return

i want i.attribute to be treated as i._ward

I get a compile error "instance has no attribute 'attribute' " which i
understand. how do i fix this

HELP
 
M

Marc 'BlackJack' Rintsch

def getAttributeForProperty(self,rollnumber,attribute):
# attribute have the value _ward
'''
If year is null then use current year. Returns the value of the
attribute for the given roll number '''
print 'Searching for attribute', attribute for index, i in
enumerate(self._aa):
if (rollnumber == i._roll_number) and ( hasattr (i,attribute) ) :
print index,i.attribute (COMPILER ERROR HERE) return i.attribute
return
print "\n"
return

i want i.attribute to be treated as i._ward

Look at the `getattr()` function.
I get a compile error "instance has no attribute 'attribute' " which i
understand. how do i fix this

It's not a compile error but a runtime error.

Ciao,
Marc 'BlackJack' Rintsch
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top