Re: Loading modules from files through C++

2014-07-08 Thread Roland Plüss
> On Wed, May 21, 2014 at 3:17 AM, Roland Plüss wrote: >> The important part are the last two lines. An important module is >> lacking the __builtins__ dictionary member so I had to add it. >> >> Hopefully this works also in Py3 should I switch some time later. But I >> guess it should seeing how

Re: Loading modules from files through C++

2014-06-03 Thread Roland Plüss
I came now a bit further with Python 3 but I'm hitting a total road-block right now with the importer in C++ which worked in Py2 but is now totally broken in Py3. In general I've got a C++ class based module which has two methods: { "find_module", ( PyCFunction )spModuleModuleLoader::cfFindModule,

Re: Loading modules from files through C++

2014-05-24 Thread Roland Plüss
> # CODE # > PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, NULL, NULL, 0, NULL, > NULL, NULL, NULL, NULL }; > > moduledef.m_name = "MyModule"; > moduledef.m_doc = "MyModule"; > pModule = PyModule_Create( &moduledef ); > PyState_AddModule( pModule, &moduledef ); > > PyRun_SimpleString( "print( gl

Re: Loading modules from files through C++

2014-05-21 Thread Roland Plüss
On 05/20/2014 07:55 PM, Chris Angelico wrote: > On Wed, May 21, 2014 at 3:17 AM, Roland Plüss wrote: >> The important part are the last two lines. An important module is >> lacking the __builtins__ dictionary member so I had to add it. >> >> Hopefully this works also in Py3 should I switch some t

Re: Loading modules from files through C++

2014-05-20 Thread Stefan Behnel
Roland Plüss, 20.05.2014 19:17: > PyObject * const loadedModule = Py_InitModule3( fullname, NULL, "Loaded > module" ); > PyObject * const moduleDict = PyModule_GetDict( loadedModule ); // > borrowed reference > PyDict_SetItemString( moduleDict, "__builtins__", PyEval_GetBuiltins() ); > PyRun_String

Re: Loading modules from files through C++

2014-05-20 Thread Chris Angelico
On Wed, May 21, 2014 at 3:17 AM, Roland Plüss wrote: > The important part are the last two lines. An important module is > lacking the __builtins__ dictionary member so I had to add it. > > Hopefully this works also in Py3 should I switch some time later. But I > guess it should seeing how simple

Re: Loading modules from files through C++

2014-05-20 Thread Roland Plüss
On 05/19/2014 03:40 AM, Chris Angelico wrote: > On Mon, May 19, 2014 at 5:41 AM, Roland Plüss wrote: >> This exec source_code in module.__dict__ , should this not also be doable >> with PyEval_EvalCode? > General principle: The more code you write in Python and the less in > C/C++, the happier an

Re: Loading modules from files through C++

2014-05-19 Thread Michael Torrie
On 05/17/2014 08:01 AM, Stefan Behnel wrote: > please avoid top-posting. Trimming quoted material where appropriate is always welcome too! -- https://mail.python.org/mailman/listinfo/python-list

Re: Loading modules from files through C++

2014-05-19 Thread Roland Plüss
On 05/19/2014 03:40 AM, Chris Angelico wrote: > On Mon, May 19, 2014 at 5:41 AM, Roland Plüss wrote: >> This exec source_code in module.__dict__ , should this not also be doable >> with PyEval_EvalCode? > General principle: The more code you write in Python and the less in > C/C++, the happier an

Re: Loading modules from files through C++

2014-05-18 Thread Chris Angelico
On Mon, May 19, 2014 at 5:41 AM, Roland Plüss wrote: > This exec source_code in module.__dict__ , should this not also be doable > with PyEval_EvalCode? General principle: The more code you write in Python and the less in C/C++, the happier and more productive you will be. Drop into Python as so

Re: Loading modules from files through C++

2014-05-18 Thread Roland Plüss
On 05/17/2014 07:05 PM, Stefan Behnel wrote: > Roland Plüss, 17.05.2014 18:28: >> On 05/17/2014 05:49 PM, Stefan Behnel wrote: >>> Roland Plüss, 17.05.2014 17:28: On 05/17/2014 04:01 PM, Stefan Behnel wrote: > Roland Plüss, 17.05.2014 15:49: >> On 05/17/2014 03:26 PM, Stefan Behnel wr

Re: Loading modules from files through C++

2014-05-17 Thread Stefan Behnel
Roland Plüss, 17.05.2014 18:28: > On 05/17/2014 05:49 PM, Stefan Behnel wrote: >> Roland Plüss, 17.05.2014 17:28: >>> On 05/17/2014 04:01 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 15:49: > On 05/17/2014 03:26 PM, Stefan Behnel wrote: >> Roland Plüss, 17.05.2014 15:00: >>> O

Re: Loading modules from files through C++

2014-05-17 Thread Roland Plüss
On 05/17/2014 05:49 PM, Stefan Behnel wrote: > Roland Plüss, 17.05.2014 17:28: >> On 05/17/2014 04:01 PM, Stefan Behnel wrote: >>> Roland Plüss, 17.05.2014 15:49: On 05/17/2014 03:26 PM, Stefan Behnel wrote: > Roland Plüss, 17.05.2014 15:00: >> On 05/17/2014 01:58 PM, Stefan Behnel wr

Re: Loading modules from files through C++

2014-05-17 Thread Stefan Behnel
Roland Plüss, 17.05.2014 17:28: > On 05/17/2014 04:01 PM, Stefan Behnel wrote: >> Roland Plüss, 17.05.2014 15:49: >>> On 05/17/2014 03:26 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 15:00: > On 05/17/2014 01:58 PM, Stefan Behnel wrote: >> Roland Plüss, 17.05.2014 02:27: >>> I

Re: Loading modules from files through C++

2014-05-17 Thread Roland Plüss
On 05/17/2014 04:01 PM, Stefan Behnel wrote: > Hi, > > please avoid top-posting. > > > Roland Plüss, 17.05.2014 15:49: >> On 05/17/2014 03:26 PM, Stefan Behnel wrote: >>> Roland Plüss, 17.05.2014 15:00: On 05/17/2014 01:58 PM, Stefan Behnel wrote: > Roland Plüss, 17.05.2014 02:27: >>

Re: Loading modules from files through C++

2014-05-17 Thread Stefan Behnel
Hi, please avoid top-posting. Roland Plüss, 17.05.2014 15:49: > On 05/17/2014 03:26 PM, Stefan Behnel wrote: >> Roland Plüss, 17.05.2014 15:00: >>> On 05/17/2014 01:58 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 02:27: > I'm using Python in an embedded situation. In particular I h

Re: Loading modules from files through C++

2014-05-17 Thread Roland Plüss
I'm willing to go to Py3 but only if the solution to the problem is simpler than getting it fixed in Py2. So some questions first: - does this importlib stuff you showed there apply to C++ land (I need to fully drive it from C++ not Python code)? - is the C++ land of Py3 similar to Py2 or totally

Re: Loading modules from files through C++

2014-05-17 Thread Stefan Behnel
Roland Plüss, 17.05.2014 15:00: > On 05/17/2014 01:58 PM, Stefan Behnel wrote: >> Roland Plüss, 17.05.2014 02:27: >>> I'm using Python in an embedded situation. In particular I have to load >>> python scripts through a memory interface so regular python module >>> loading can not be used. I got wor

Re: Loading modules from files through C++

2014-05-17 Thread Roland Plüss
That doesn't work in 2.x, doesn't it? On 05/17/2014 01:58 PM, Stefan Behnel wrote: > Roland Plüss, 17.05.2014 02:27: >> I'm using Python in an embedded situation. In particular I have to load >> python scripts through a memory interface so regular python module >> loading can not be used. I got wo

Re: Loading modules from files through C++

2014-05-17 Thread Stefan Behnel
Roland Plüss, 17.05.2014 02:27: > I'm using Python in an embedded situation. In particular I have to load > python scripts through a memory interface so regular python module > loading can not be used. I got working so far a module loader object > I've added using C++ to sys.meta_path . Now I'm tot

Loading modules from files through C++

2014-05-16 Thread Roland Plüss
I'm using Python in an embedded situation. In particular I have to load python scripts through a memory interface so regular python module loading can not be used. I got working so far a module loader object I've added using C++ to sys.meta_path . Now I'm totally stuck at the finally loading step.

Re: Error with co_filename when loading modules from zip file

2012-03-06 Thread Peter Otten
Bob Rossi wrote: > On Tue, Mar 06, 2012 at 02:38:50AM -0800, Vinay Sajip wrote: >> On Mar 6, 2:40 am, Bob Rossi wrote: >> >> > Darn it, this was reported in 2007 >> > http://bugs.python.org/issue1180193 >> > and it was mentioned the logging package was effected. >> > >> > Yikes. >> > >> >> I wi

Re: Error with co_filename when loading modules from zip file

2012-03-06 Thread Bob Rossi
On Tue, Mar 06, 2012 at 02:38:50AM -0800, Vinay Sajip wrote: > On Mar 6, 2:40 am, Bob Rossi wrote: > > > Darn it, this was reported in 2007 > >  http://bugs.python.org/issue1180193 > > and it was mentioned the logging package was effected. > > > > Yikes. > > > > I will think about this, but don'

Re: Error with co_filename when loading modules from zip file

2012-03-06 Thread Vinay Sajip
On Mar 6, 2:40 am, Bob Rossi wrote: > Darn it, this was reported in 2007 >  http://bugs.python.org/issue1180193 > and it was mentioned the logging package was effected. > > Yikes. > I will think about this, but don't expect any quick resolution :-( I think the right fix would be not in the loggi

Re: Error with co_filename when loading modules from zip file

2012-03-05 Thread Bob Rossi
On Mon, Mar 05, 2012 at 02:22:55PM -0800, Vinay Sajip wrote: > On Mar 5, 8:36 pm, Bob wrote: > > > The logging package gets the filename and line number > > of the calling function by looking at two variables, the filename > > of the frame in the stack trace and the variable logging._srcfile. > >

Re: Error with co_filename when loading modules from zip file

2012-03-05 Thread Bob Rossi
On Mon, Mar 05, 2012 at 02:22:55PM -0800, Vinay Sajip wrote: > On Mar 5, 8:36 pm, Bob wrote: > > > The logging package gets the filename and line number > > of the calling function by looking at two variables, the filename > > of the frame in the stack trace and the variable logging._srcfile. > >

Re: Error with co_filename when loading modules from zip file

2012-03-05 Thread Vinay Sajip
On Mar 5, 8:36 pm, Bob wrote: > The logging package gets the filename and line number > of the calling function by looking at two variables, the filename > of the frame in the stack trace and the variable logging._srcfile. > The comparison is done in logging/__init__.py:findCaller. > The _srcfil

Error with co_filename when loading modules from zip file

2012-03-05 Thread Bob
Hi, I'm using a program that distributes python in a zip file and ran into an issue with the logging package. It seems to return the wrong filename/line number when loading python from a zip file. Please help! I'm using python31, and have copied the lib directory to /home/user/python3.1 and hav

Re: Loading Modules

2011-04-13 Thread Peter Otten
Cornelius Kölbel wrote: > I am wondering about loading modules.What is a good way of doing this? > > In my code I got one single function, where I need some functionality > from a built-in module. built-in modules are always imported by definition, so you cannot save space or time by moving the

Loading Modules

2011-04-13 Thread Cornelius Kölbel
Hello list, I am wondering about loading modules.What is a good way of doing this? In my code I got one single function, where I need some functionality from a built-in module. Is it a better way to load the module only within the function pro: the function will only be hit every now and then

Re: CPython loading modules into memory

2009-02-11 Thread sjbrown
On Feb 11, 2:00 pm, "Martin v. Löwis" wrote: > > Can someone describe the details of how Python loads modules into > > memory?  I assume once the .py file is compiled to .pyc that it is > > mmap'ed in.  But that assumption is very naive.  Maybe it uses an > > anonymous mapping?  Maybe it does othe

Re: CPython loading modules into memory

2009-02-11 Thread Martin v. Löwis
> Can someone describe the details of how Python loads modules into > memory? I assume once the .py file is compiled to .pyc that it is > mmap'ed in. But that assumption is very naive. Maybe it uses an > anonymous mapping? Maybe it does other special magic? This is all > very alien to me, so i

Re: CPython loading modules into memory

2009-02-11 Thread Robert Kern
On 2009-02-11 15:30, sjbrown wrote: Can someone describe the details of how Python loads modules into memory? I assume once the .py file is compiled to .pyc that it is mmap'ed in. But that assumption is very naive. Maybe it uses an anonymous mapping? Maybe it does other special magic? This i

CPython loading modules into memory

2009-02-11 Thread sjbrown
Can someone describe the details of how Python loads modules into memory? I assume once the .py file is compiled to .pyc that it is mmap'ed in. But that assumption is very naive. Maybe it uses an anonymous mapping? Maybe it does other special magic? This is all very alien to me, so if someone

Re: Dynamic Loading Modules

2009-01-18 Thread Laszlo Nagy
Riley Porter írta: Hello all, This is the first time I have posted to this group. That being said if I am in the wrong place for this kind of support please let me know. OK, So I am writing a log parsing program and wish to allow for the community to write "parsers". Basically, what I ha

Dynamic Loading Modules

2009-01-17 Thread Riley Porter
Hello all, This is the first time I have posted to this group. That being said if I am in the wrong place for this kind of support please let me know. OK, So I am writing a log parsing program and wish to allow for the community to write "parsers". Basically, what I have in place now is a "mod

Re: loading modules, metaclasses, chicken & eggs

2008-11-12 Thread Aaron Brady
On Nov 12, 3:01 pm, sandro <[EMAIL PROTECTED]> wrote: > Aaron Brady wrote: > > On Nov 12, 9:38 am, sandro <[EMAIL PROTECTED] wrote: > >> Hi, > >> Is there a way to solve this? I'd like ro force a reload of the > >> metaclass after 'debug'  has been loaded and debug.DBG set to True, > >> but that do

Re: loading modules, metaclasses, chicken & eggs

2008-11-12 Thread sandro
Aaron Brady wrote: > On Nov 12, 9:38 am, sandro <[EMAIL PROTECTED] wrote: >> Hi, >> Is there a way to solve this? I'd like ro force a reload of the >> metaclass after 'debug'  has been loaded and debug.DBG set to True, >> but that doesn't seem to happen... >> >> Any hints? >> >> sandro >> *:-) >>

Re: loading modules, metaclasses, chicken & eggs

2008-11-12 Thread Aaron Brady
On Nov 12, 9:38 am, sandro <[EMAIL PROTECTED]> wrote: > Hi, > Is there a way to solve this? I'd like ro force a reload of the > metaclass after 'debug'  has been loaded and debug.DBG set to True, > but that doesn't seem to happen... > > Any hints? > > sandro > *:-) > > sqlkit:  http://sqlkit.argoli

loading modules, metaclasses, chicken & eggs

2008-11-12 Thread sandro
Hi, I had two packages working fine toghether: debug and sqlkit. Debug provides a metaclass just for debuggging purposes to sqlkit (to log methods following a recipe on ASPN. It worked very well, just logging depending on the value of a module variable in debug module. That means module debug a

Re: Error loading modules

2008-11-06 Thread M.-A. Lemburg
The easiest way to debug such import problems is by telling Python to be verbose: python -vv -c "import some_module" The generated output will then list all the locations where Python looks for the module and is often handy to track down reasons for Python not being able to load a module. -- Ma

Re: Error loading modules

2008-11-05 Thread John Machin
On Nov 6, 3:21 am, BL <[EMAIL PROTECTED]> wrote: > On Nov 4, 7:11 pm, John Machin <[EMAIL PROTECTED]> wrote: > > > > > On Nov 5, 9:18 am, BL <[EMAIL PROTECTED]> wrote: > > > > I am very new to python.  I am installing it as part of a bazzar > > > version control installation. > > > I have installed

Re: Error loading modules

2008-11-05 Thread BL
On Nov 4, 7:11 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Nov 5, 9:18 am, BL <[EMAIL PROTECTED]> wrote: > > > I am very new to python.  I am installing it as part of a bazzar > > version control installation. > > I have installed the Crypto, paramiko and cElementTree modules.  I am > > running

Re: Error loading modules

2008-11-04 Thread John Machin
On Nov 5, 9:18 am, BL <[EMAIL PROTECTED]> wrote: > I am very new to python.  I am installing it as part of a bazzar > version control installation. > I have installed the Crypto, paramiko and cElementTree modules.  I am > running Solaris10x86. > When testing the modules I get the following results.

Error loading modules

2008-11-04 Thread BL
I am very new to python. I am installing it as part of a bazzar version control installation. I have installed the Crypto, paramiko and cElementTree modules. I am running Solaris10x86. When testing the modules I get the following results. python -c "import Crypto" Traceback (most recent call la

Re: problems loading modules

2007-02-06 Thread Frank
Thanks guys! -- http://mail.python.org/mailman/listinfo/python-list

Re: problems loading modules

2007-02-04 Thread Ganesan Rajagopal
> Frank <[EMAIL PROTECTED]> writes: import random from numpy import * print random.randrange(10) > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'module' object has no attribute 'randrange' > Here it does not work. Here's a clue. =

Re: problems loading modules

2007-02-04 Thread Ben Finney
"Frank" <[EMAIL PROTECTED]> writes: > >>> import random > >>> print random.randrange(10) > 8 > >>> > > Everything is fine. > > >>> import random > >>> from numpy import * > >>> > >>> print random.randrange(10) > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'module'

Re: problems loading modules

2007-02-04 Thread Robert Kern
Frank wrote: > Hi, > > I have the following weird behavior when I load modules: > > import random print random.randrange(10) > 8 > > Everything is fine. > import random from numpy import * print random.randrange(10) > Traceback (most recent call last): > File "",

problems loading modules

2007-02-04 Thread Frank
Hi, I have the following weird behavior when I load modules: >>> import random >>> print random.randrange(10) 8 >>> Everything is fine. >>> import random >>> from numpy import * >>> >>> print random.randrange(10) Traceback (most recent call last): File "", line 1, in ? AttributeError: 'module

Re: loading modules in debug

2006-01-30 Thread [EMAIL PROTECTED]
[I haven't seen an answer for this older question, so I figured I'd go ahead and post one] Andras Balogh wrote: > > The problem is that, in debug mode, Python expects every module name to > be postfixed with _d, which makes my dynamic loading (using LoadLibrary) > not work, unless I #ifdef it ever

loading modules in debug

2006-01-26 Thread Andras Balogh
The project I'm working on is written mainly C/C++, spiced with some Python scripts. Now, I have several dlls, which work both as a Python extension modules, exporting functions to Python via "initmodule", and as normal dynamic libraries, to which I link dynamically from within my C program. T