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

convert string literal to object attribute

P: n/a
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
Oct 31 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Fri, 31 Oct 2008 11:40:02 -0700, BiraRai wrote:
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
Oct 31 '08 #2

P: n/a
On Oct 31, 3:00*pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Fri, 31 Oct 2008 11:40:02 -0700, BiraRai wrote:
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
Thanks Marc, worked great.

Oct 31 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.