Embedding Python

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

    #1

    Embedding Python

    Dear Pythoners,

    I am writing as I am having trouble embedding a Python program into a
    Win XP C++ console application.

    I have written a script file for importing and I am trying to use the
    example for "Pure Embedding" found in the product documentation.

    The program fails to successfully execute past the line:

    if (pFunc && PyCallable_Chec k(pFunc))

    I have checked the pFunc pointer at runtime and it is not null so I
    assume that the PyCallable_Chec k fails.

    If I define my function in python in file "multiply.p y" as:

    def multiply(a,b):
    print "Will compute", a, "times", b
    c = 0
    for i in range(0, a):
    c = c + b
    return c

    Then in VC++ I call the program with arguments:

    multiply multiply 23 3

    Then I'd expect a successful result, the file seems to be getting
    parsed if multiply.pyc is available, but the function multiply does
    not seem to be callable - where am I going wrong?






  • Serge Orlov

    #2
    Re: Embedding Python

    gavinpaterson wrote:[color=blue]
    > Dear Pythoners,
    >
    > I am writing as I am having trouble embedding a Python program into a
    > Win XP C++ console application.
    >
    > I have written a script file for importing and I am trying to use the
    > example for "Pure Embedding" found in the product documentation.
    >
    > The program fails to successfully execute past the line:
    >
    > if (pFunc && PyCallable_Chec k(pFunc))
    >
    > I have checked the pFunc pointer at runtime and it is not null so I
    > assume that the PyCallable_Chec k fails.[/color]

    Looking at the source in "Pure Embedding" I see that it is supposed to
    print an error message if PyCallable_Chec k fails, have you got the
    message?

    Comment

    Working...