Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Strange error with getattr() function

Reply
Thread Tools

Strange error with getattr() function

 
 
Hole
Guest
Posts: n/a
 
      12-18-2006
Hi There!

I'm trying to use Zope and the product OpenFlow.

I got the following error while I was using the built-in function
getattr() to retrieve an OpenFlow object:

attribute name must be string


Actually, I surely pass a string as attribute name to getattr()

The code:

#following instruction returns me the string "WorkFlowTest"
openflow_id=container.aq_parent.id

if (hasattr(container,openflow_id):
#the interpreter enter in this block, so
#it's sure that container has an attribute called WorkFlowTest
openflow=getattr(container,openflow_id)

At this point, I got the error: attribute name must be string

The *strange* is that I get the same error even if I pass the attribute
name to the getattr() function as pure string:

getattr(container,"WorkFlowTest")

(sic!!!!!)

I'm a lot confused!
Thanks in advance.

--
H0le

 
Reply With Quote
 
 
 
 
Hole
Guest
Posts: n/a
 
      12-18-2006

Hole ha scritto:

> Hi There!
>
> I'm trying to use Zope and the product OpenFlow.
>
> I got the following error while I was using the built-in function
> getattr() to retrieve an OpenFlow object:
>
> attribute name must be string
>
>
> Actually, I surely pass a string as attribute name to getattr()
>
> The code:
>
> #following instruction returns me the string "WorkFlowTest"
> openflow_id=container.aq_parent.id
>
> if (hasattr(container,openflow_id):
> #the interpreter enter in this block, so
> #it's sure that container has an attribute called WorkFlowTest
> openflow=getattr(container,openflow_id)
>
> At this point, I got the error: attribute name must be string
>


I'm wondering if the exception is raised in a hidden function and not
in the explicit call to getattr(). How can I view the traceback in a
script running in zope??

 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      12-18-2006
At Monday 18/12/2006 12:33, Hole wrote:

>I'm trying to use Zope and the product OpenFlow.


Try posting in the Zope list, you surely will have more responses.

>I got the following error while I was using the built-in function
>getattr() to retrieve an OpenFlow object:
>
>attribute name must be string
>
>
>Actually, I surely pass a string as attribute name to getattr()
>
>The code:
>
>#following instruction returns me the string "WorkFlowTest"
>openflow_id=container.aq_parent.id


Are you sure it's a string? Some objects have an id() method. You
always should use getId().

>if (hasattr(container,openflow_id):
> #the interpreter enter in this block, so
> #it's sure that container has an attribute called WorkFlowTest
> openflow=getattr(container,openflow_id)
>
>At this point, I got the error: attribute name must be string


getattr is acquisition-aware so you might be retrieving another thing...

>The *strange* is that I get the same error even if I pass the attribute
>name to the getattr() function as pure string:
>
>getattr(container,"WorkFlowTest")
>(sic!!!!!)


If you're really sure of this, I think the error may occur inside
another function in the getattr chain.



--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      12-18-2006
At Monday 18/12/2006 13:25, Hole wrote:

> > At this point, I got the error: attribute name must be string

>
>I'm wondering if the exception is raised in a hidden function and not
>in the explicit call to getattr(). How can I view the traceback in a
>script running in zope??


(Which Zope version?)
If you don't catch the exception, an error page will be displayed,
pointing to the error_log object.


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

 
Reply With Quote
 
Hole
Guest
Posts: n/a
 
      12-19-2006

Gabriel Genellina ha scritto:

> At Monday 18/12/2006 13:25, Hole wrote:
>
> > > At this point, I got the error: attribute name must be string

> >
> >I'm wondering if the exception is raised in a hidden function and not
> >in the explicit call to getattr(). How can I view the traceback in a
> >script running in zope??

>
> (Which Zope version?)
> If you don't catch the exception, an error page will be displayed,
> pointing to the error_log object.
>
>


Hi Gabriel,

thanks a lot for your replies.

I've resolved the problem catching the exception and printing the
traceback in a file.

The problem was, indeed, in a getattr() call performed in another
function, to which I passed an int rather than a string.

Bye!

--
DN

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A strange string function error jacklisp@gmail.com C Programming 7 11-08-2008 09:53 PM
Strange Perl line : Return the result of a function to a function AlexHWGUY Perl Misc 5 10-24-2006 09:27 PM
Strange Error in Function Tony ASP General 3 06-17-2005 02:05 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Question About Strange 'C' Code Syntax ( Well strange to me anyway ) Harvey Twyman C Programming 8 10-25-2003 05:54 AM



Advertisments