Strange error with getattr() function

Discussion in 'Python' started by Hole, Dec 18, 2006.

  1. Hole

    Hole Guest

    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
    Hole, Dec 18, 2006
    #1
    1. Advertising

  2. Hole

    Hole Guest

    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??
    Hole, Dec 18, 2006
    #2
    1. Advertising

  3. 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
    Gabriel Genellina, Dec 18, 2006
    #3
  4. 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
    Gabriel Genellina, Dec 18, 2006
    #4
  5. Hole

    Hole Guest

    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
    Hole, Dec 19, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pierre
    Replies:
    13
    Views:
    624
    Ben Finney
    May 18, 2006
  2. Nathan Harmston

    recursion error using setattr and getattr

    Nathan Harmston, Jun 7, 2007, in forum: Python
    Replies:
    0
    Views:
    286
    Nathan Harmston
    Jun 7, 2007
  3. Sergio Correia
    Replies:
    1
    Views:
    627
    Alex Martelli
    Sep 4, 2007
  4. Mr SZ

    getattr on a function

    Mr SZ, Apr 27, 2009, in forum: Python
    Replies:
    2
    Views:
    267
    John Machin
    Apr 27, 2009
  5. Catherine M Moroney
    Replies:
    5
    Views:
    94
    Gregory Ewing
    Nov 22, 2013
Loading...

Share This Page