473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

convert string literal to object attribute

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
2 2913
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: flyaflya | last post by:
a = "(1,2,3)" I want convert a to tuple:(1,2,3),but tuple(a) return ('(', '1', ',', '2', ',', '3', ')') not (1,2,3)
5
by: Negroup | last post by:
Hi all. I'm writing a simple Python module containing functions to process strings in various ways. Actually it works importing the module that contains the function I'm interested in, and calling...
1
by: Alastair Cameron | last post by:
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the...
16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
5
by: manmit.walia | last post by:
Hello All, I am stuck on a conversion problem. I am trying to convert my application which is written in VB.NET to C# because the project I am working on currently is being written in C#. I tried...
10
by: Farshid Lashkari | last post by:
When I pass an empty string to a function is a new string object created or does python use some global pre-created object? I know python does this with integer objects under a certain value. For...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
26
by: anonieko | last post by:
In the past I always used "" everywhere for empty string in my code without a problem. Now, do you think I should use String.Empty instead of "" (at all times) ? Let me know your thoughts.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.