strange TypeError exception in function compiled from a string

Discussion in 'Python' started by nelson, Dec 1, 2010.

  1. nelson

    nelson Guest

    Hi all,
    I have this function, defined in a string and ecetuted through ad
    exec call

    def cell1(d):

    x=d.get('x')
    print x

    import y
    return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x))


    d is a dict of this kind {'x':2}

    I receive the following exception, that i find very strange...

    File "<string>", line 7, in cell1
    TypeError: 'dict' object is not callable

    I have tested all the function al line 7, and none of them raise any
    exception.
    Have anyone some suggestion on how to solve this?

    thanks!
     
    nelson, Dec 1, 2010
    #1
    1. Advertising

  2. nelson

    Guest

    Re: strange TypeError exception in function compiled from a string

    On 1 déc, 14:48, nelson <> wrote:
    > Hi all,
    >   I have this function, defined in a string and ecetuted through ad
    > exec call
    >
    > def cell1(d):
    >
    >     x=d.get('x')
    >     print x
    >
    >     import y
    >     return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x))
    >
    > d is a dict of this kind {'x':2}
    >
    > I receive the following exception, that i find very strange...
    >
    >   File "<string>", line 7, in cell1
    > TypeError: 'dict' object is not callable
    >
    > I have tested all the function al line 7, and none of them raise any
    > exception.
    > Have anyone some suggestion on how to solve this?
    >


    Not without the minimal executable code reproducing your error.
     
    , Dec 1, 2010
    #2
    1. Advertising

  3. nelson

    MRAB Guest

    On 01/12/2010 13:48, nelson wrote:
    > Hi all,
    > I have this function, defined in a string and ecetuted through ad
    > exec call
    >
    > def cell1(d):
    >
    > x=d.get('x')
    > print x
    >
    > import y
    > return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x))
    >
    >
    > d is a dict of this kind {'x':2}
    >
    > I receive the following exception, that i find very strange...
    >
    > File "<string>", line 7, in cell1
    > TypeError: 'dict' object is not callable
    >
    > I have tested all the function al line 7, and none of them raise any
    > exception.
    > Have anyone some suggestion on how to solve this?
    >

    A call looks like foo(), so probably either y.add or self.adf0 is a
    dict. Print both of them to check.
     
    MRAB, Dec 1, 2010
    #3
  4. nelson <> writes:


    > Hi all,
    > I have this function, defined in a string and ecetuted through ad
    > exec call
    >
    > def cell1(d):
    >
    > x=d.get('x')
    > print x
    >
    > import y
    > return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x))
    >

    What is self in line 7?
    --
    Piet van Oostrum <>
    WWW: http://pietvanoostrum.com/
    PGP key: [8DAE142BE17999C4]
    Nu Fair Trade woonartikelen op http://www.zylja.com
     
    Piet van Oostrum, Dec 2, 2010
    #4
    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. Klaus Schneider
    Replies:
    1
    Views:
    563
    Rolf Magnus
    Dec 2, 2004
  2. Tim Isakson

    Newbie question: Strange TypeError

    Tim Isakson, Jul 7, 2003, in forum: Python
    Replies:
    2
    Views:
    307
    Adrien Di Mascio
    Jul 7, 2003
  3. lander
    Replies:
    5
    Views:
    608
    bruce barker
    Mar 5, 2008
  4. Sergey Kishchenko
    Replies:
    6
    Views:
    312
    Terry Reedy
    Jan 9, 2009
  5. Victor Hooi
    Replies:
    4
    Views:
    326
Loading...

Share This Page