Re: help! Troubled when embed python into C++

Discussion in 'Python' started by A. Cavallo, May 24, 2009.

  1. A. Cavallo

    A. Cavallo Guest

    You need the:

    int main(int argc, char * argv[])
    {
    Py_Initialize();
    PySys_SetArgv(argc, argv);
    PyRun_SimpleString("execfile(r'1.py')");
    Py_Finalize();
    return 0;
    }


    Regards,
    Antonio

    On Sunday 24 May 2009 11:42:13 孟炜 wrote:
    > I have the following codes in C++:
    > #include <Python.h>
    > void main(){
    > Py_Initialize();
    > PyRun_SimpleString("execfile(r'1.py')");
    > Py_Finalize();
    > return;
    > }
    >
    > the following is in 1.py :
    > import Tkinter
    > root=Tkinter.Tk()
    > root2=Tkinter.Tk()
    > root.mainloop()
    > root2.mainloop()
    >
    > this is the output after I run the c++ program:
    > Traceback (most recent call last):
    > File " <string>", line 1, in <module>
    > File "g:\volatile\1.py", line 2, in <module>
    > root=Tkinter.Tk()
    > File "C:\Python26\lib\lib-tk\Tkinter.py", line 1638, i
    > baseName = os.path.basename(sys.argv[0])
    > AttributeError: 'module' object has no attribute 'argv'
    >
    > I am quite new to python ,anyone know what shoud i do to solve it?
    > Thanks a lot!
     
    A. Cavallo, May 24, 2009
    #1
    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. jstack
    Replies:
    1
    Views:
    619
    Tor Iver Wilhelmsen
    Jul 4, 2003
  2. disgracelands

    Trying to embed python into C, help!

    disgracelands, Aug 10, 2003, in forum: Python
    Replies:
    2
    Views:
    368
    Syver Enstad
    Aug 10, 2003
  3. Replies:
    3
    Views:
    429
    Matt Humphrey
    Sep 23, 2006
  4. Benton
    Replies:
    1
    Views:
    321
    Mark Fitzpatrick
    Mar 24, 2007
  5. Ryniek90
    Replies:
    1
    Views:
    435
    André
    Jul 29, 2009
Loading...

Share This Page