Extending Embedded Python and execute external script

Discussion in 'Python' started by Vertilka, Jan 4, 2007.

  1. Vertilka

    Vertilka Guest

    What i need from my C application to do ?
    1) To execute a python script from file.
    2) The python script will call functions in my C application.

    According to the answer from Ravi Teja (topic "C app and Python"), I
    need to extend embedded python in my C application.

    I saw several functions: PyRun_AnyFileExFlags, PyRun_SimpleFileExFlags,
    PyRun_FileExFlags.

    Questions:
    1) Which one should i use in order to achieve what i need ?
    2) I couldn't understand the differance betwwen the three ?
    3) What is the difference between the "FILE *fp" and "const char
    *filename" arguments of these functions. If i give a FILE*, why do i
    need to give the file name ?

    Tnx,
    Vertilka
    Vertilka, Jan 4, 2007
    #1
    1. Advertising

  2. "Vertilka" <> wrote:

    > I saw several functions: PyRun_AnyFileExFlags, PyRun_SimpleFileExFlags,
    > PyRun_FileExFlags.
    >
    > Questions:
    > 1) Which one should i use in order to achieve what i need ?


    PyRun_SimpleFile or PyRun_SimpleString should be good enough. Using
    SimpleString is more robust:

    http://effbot.org/pyfaq/pyrun-simplefile-crashes-on-windows-but-not-on-unix-why.htm

    and also lets you implement additional glue in Python code instead of in C/C++.

    > 2) I couldn't understand the differance betwwen the three ?


    AnyFile supports interactive devices, RunFile requires you to provide a custom
    execution context.

    > 3) What is the difference between the "FILE *fp" and "const char
    > *filename" arguments of these functions. If i give a FILE*, why do i
    > need to give the file name ?


    Python needs the filename to be able to give meaningful error messages.

    </F>
    Fredrik Lundh, Jan 4, 2007
    #2
    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. Carl Douglas
    Replies:
    0
    Views:
    335
    Carl Douglas
    Feb 19, 2007
  2. Carl Douglas
    Replies:
    0
    Views:
    386
    Carl Douglas
    Mar 5, 2007
  3. johnny
    Replies:
    5
    Views:
    485
    Antonio Cuni
    Jul 11, 2007
  4. Rajat
    Replies:
    3
    Views:
    672
    Jorgen Grahn
    Jan 8, 2010
  5. VYAS ASHISH M-NTB837
    Replies:
    2
    Views:
    528
    Jan Kaliszewski
    Jan 7, 2010
Loading...

Share This Page