Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-02-09 Thread greg
Ben Sizer wrote: Yes, this seems to fix it, thanks. But why? Can some Python guru explain why these two dictionaries must be the same? (Or what steps we must take if we want them to be separate?) What's happening is that the import statement is binding the name 'sys' in the locals, not the glob

Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-21 Thread Aahz
In article , Ben Sizer wrote: > >I have the following C++ code and am attempting to embed Python 2.5, >but although the "import sys" statement works, attempting to reference >"sys.path" from inside a function after that point fails. It's as if >it's not treating it as a normal module but as any o

Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-15 Thread Ben Sizer
On Jan 14, 4:37 pm, Ivan Illarionov wrote: > On Jan 14, 1:49 pm, Ben Sizer wrote: > > > No, I don't want to do anything with sys.path apart from see it. I > > just wanted my original question answered, not a guess at my intent > > and a solution for something I'm not doing. ;) Thanks though! > >

Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-14 Thread Ivan Illarionov
On Jan 14, 8:17 pm, Ivan Illarionov wrote: > On Jan 14, 8:00 pm, Ben Sizer wrote: > > > I will try it when I get home. However I would like to be able to > > treat them as separate dictionaries, as I want to be able to import > > some symbols and modules at a global level, but be able to clear ou

Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-14 Thread Ivan Illarionov
On Jan 14, 8:00 pm, Ben Sizer wrote: > I will try it when I get home. However I would like to be able to > treat them as separate dictionaries, as I want to be able to import > some symbols and modules at a global level, but be able to clear out > objects introduced at the local level on a periodi

Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-14 Thread Ben Sizer
On Jan 14, 4:37 pm, Ivan Illarionov wrote: > > I would try to use ourNamespace_ dict for > both globals and locals in PyRun_String call. I will try it when I get home. However I would like to be able to treat them as separate dictionaries, as I want to be able to import some symbols and modules a

Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-14 Thread Ivan Illarionov
On Jan 14, 1:49 pm, Ben Sizer wrote: > No, I don't want to do anything with sys.path apart from see it. I > just wanted my original question answered, not a guess at my intent > and a solution for something I'm not doing. ;)  Thanks though! > > Again - why can I not reference sys from within the f

Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-14 Thread Ben Sizer
On Jan 14, 1:55 am, Ivan Illarionov wrote: > Ben Sizer wrote: > > What am I doing wrong? > > What are you trying to achieve? > If you want to modify sys.path I suggest using Python/C API directly: No, I don't want to do anything with sys.path apart from see it. I just wanted my original question

Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-13 Thread Christian Heimes
Ivan Illarionov schrieb: > Ben Sizer wrote: >> What am I doing wrong? > > What are you trying to achieve? > If you want to modify sys.path I suggest using Python/C API directly: > (boilerplate removed) > PyImport_ImportModule("sys") > PyObject_GetAttrString(sysmod_pointer, "path") > PyList_Insert

Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-13 Thread Ivan Illarionov
Ben Sizer wrote: > What am I doing wrong? What are you trying to achieve? If you want to modify sys.path I suggest using Python/C API directly: (boilerplate removed) PyImport_ImportModule("sys") PyObject_GetAttrString(sysmod_pointer, "path") PyList_Insert(pathobj_pointer, 0, path_python_str) --

'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-13 Thread Ben Sizer
I have the following C++ code and am attempting to embed Python 2.5, but although the "import sys" statement works, attempting to reference "sys.path" from inside a function after that point fails. It's as if it's not treating it as a normal module but as any other global variable which I'd have to