PyRun_SimpleString no sys.argv[0]

I

iwl

Hello,

I'm just starting with Python - would like to embed it in my
windows-programm as an script-processor. For tests I use easygui some
easy-wrapper for the py-tck-stuff.

PyRun_SimpleString("from easygui import *\n");
PyRun_SimpleString("import sys\n");
PyRun_SimpleString("msgbox()\n");

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "easygui.py", line 148, in msgbox
reply = buttonbox(message, title, choices)
File "easygui.py", line 170, in buttonbox
root = Tk()
File "C:\Python\Python25\Lib\lib-tk\Tkinter.py", line 1631, in
__init__
baseName = os.path.basename(sys.argv[0])
AttributeError: 'module' object has no attribute 'argv'

May bee makes some sence that the embedded Interpreter has no argv[0],
however tk seems not to bee ready for that.
I try to define some sys.argv[0] myself after I get out how to do that,
maybee someone other has an better idea until than.
 
G

Gabriel Genellina

I'm just starting with Python - would like to embed it in my
windows-programm as an script-processor. For tests I use easygui some
easy-wrapper for the py-tck-stuff.

Looks a bit strange for me. If the GUI will be in Python, I think you
could do things the other way, *extending* your main Python program
with your own C code, not *embedding* Python inside your main C program.
I'm not sure if Tk can run without a mainloop.

Anyway, to answer your actual question:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "easygui.py", line 148, in msgbox
reply = buttonbox(message, title, choices)
File "easygui.py", line 170, in buttonbox
root = Tk()
File "C:\Python\Python25\Lib\lib-tk\Tkinter.py", line 1631, in
__init__
baseName = os.path.basename(sys.argv[0])
AttributeError: 'module' object has no attribute 'argv'

May bee makes some sence that the embedded Interpreter has no argv[0],
however tk seems not to bee ready for that.
I try to define some sys.argv[0] myself after I get out how to do that,
maybee someone other has an better idea until than.

From the Python/C API Reference Manual, section "Embedding Python"
(that I hope you have already read):
Py_Initialize() does not set the ``script argument list'' (sys.argv).
If this variable is needed by Python code that will be executed
later, it must be set explicitly with a call to PySys_SetArgv(argc,
argv) subsequent to the call to Py_Initialize().


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
G

Gabriel Genellina

Please keep posting on this list, surely other people can help more than I.

No I have an Borland C++ GUI Windows App and should make it scriptable
I tryed using MS ScriptControl first but have only Problems with now I
try phyton which also have more posibillities.
May bee I find a way to also access my script engine from outside
my programm. Open and connecting some kind of terminal for my embedded
phyton would also be fine.

Embedding Python into your app seems fine - but in this case, your
example (using Tk) is not a good starting point, since python wont
use a GUI (your App is the GUI).


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top