Calling python function from C and import questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sndive@gmail.com

    #1

    Calling python function from C and import questions

    Is there a better way to make a call from C than

    PyRun_SimpleStr ing("import
    foo_in_python\n foo_in_python.b ar(whatever)\n" );

    ?

    I already imported the foo_in_python using PyImport_Import Module
    and wonder why do I need to keep importing it every time I'm
    calling a python function in that module.

    I stepped thru PyImport_Import Module and it seems rather expensive.

    I assume the module will end up in cache after PyImport_Import Module
    so that subsequent
    PyRun_SimpleStr ing("import foo_in_python\n ...
    is cheaper but I still have to wonder if I what I'm doing is the right
    thing or there is a much simpler way of doing this.

    Does anyone know why does the import tries to load .py files before
    ..pyc?
    Thank you.

  • Gabriel Genellina

    #2
    Re: Calling python function from C and import questions

    <sndive@gmail.c omescribió en el mensaje
    news:1169844647 .673719.25810@j 27g2000cwj.goog legroups.com...
    Is there a better way to make a call from C than
    >
    PyRun_SimpleStr ing("import
    foo_in_python\n foo_in_python.b ar(whatever)\n" );
    >
    I already imported the foo_in_python using PyImport_Import Module
    and wonder why do I need to keep importing it every time I'm
    calling a python function in that module.
    Sure. Use the reference to the module that you got from
    PyImport_Import Module; you call a method using PyObject_CallMe thod or
    similar.
    Does anyone know why does the import tries to load .py files before
    .pyc?
    It has to be sure that the .pyc is up-to-date; the .pyc contains a magic
    number and the modification time of the corresponding .py

    --
    Gabriel Genellina


    Comment

    Working...