call static function from extension module - syntaxerror

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Todd

    #1

    call static function from extension module - syntaxerror

    Hi,

    I'm working right from the example here to make a basic extenstion
    module.



    I can load my module into python and dir shows my function. But I get
    a syntax error if I try to access it.
    [color=blue][color=green][color=darkred]
    >>> ast_man.exec[/color][/color][/color]
    File "<stdin>", line 1
    ast_man.exec
    ^
    SyntaxError: invalid syntax

    However, I can get at it using getattr. I tried compiling myself and
    using setup. My method is defined as

    static PyMethodDef ast_man_methods[] = {
    {"exec",exec,ME TH_VARARGS,"Exe cute Asterisk commands."},
    {NULL,NULL,0,NU LL}
    };

    What might be my problem??

    thanks

  • Erik Max Francis

    #2
    Re: call static function from extension module - syntaxerror

    Todd wrote:
    [color=blue]
    > I'm working right from the example here to make a basic extenstion
    > module.
    > http://docs.python.org/ext/intro.html
    > http://www.dalkescientific.com/writi...ng_python.html
    >
    > I can load my module into python and dir shows my function. But I get
    > a syntax error if I try to access it.
    >[color=green][color=darkred]
    >>>> ast_man.exec[/color][/color]
    > File "<stdin>", line 1
    > ast_man.exec
    > ^
    > SyntaxError: invalid syntax
    >
    > However, I can get at it using getattr. I tried compiling myself and
    > using setup. My method is defined as
    >
    > static PyMethodDef ast_man_methods[] = {
    > {"exec",exec,ME TH_VARARGS,"Exe cute Asterisk commands."},
    > {NULL,NULL,0,NU LL}
    > };
    >
    > What might be my problem??[/color]

    exec is a reserved word.
    [color=blue][color=green][color=darkred]
    >>> exec 'print 1'[/color][/color][/color]
    1[color=blue][color=green][color=darkred]
    >>> exec = 1[/color][/color][/color]
    File "<stdin>", line 1
    exec = 1
    ^
    SyntaxError: invalid syntax

    --
    Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
    San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
    We have lingered long enough on the shores of the cosmic ocean.
    -- Carl Sagan, 1934-1996

    Comment

    Working...