convert string literal to object attribute

BiraRai birarai at gmail.com
Fri Oct 31 14:40:02 EDT 2008


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



More information about the Python-list mailing list