[Python-Dev] Choosing a best practice solution for Python/extension modules (original) (raw)
Steven Bethard steven.bethard at gmail.com
Sun Feb 22 19:16:18 CET 2009
- Previous message: [Python-Dev] Choosing a best practice solution for Python/extension modules
- Next message: [Python-Dev] Choosing a best practice solution for Python/extension modules
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Feb 20, 2009 at 1:45 PM, Brett Cannon <brett at python.org> wrote:
But there is another issue with this: the pure Python code will never call the extension code because the globals will be bound to pypickle and not pickle. So if you have something like::
# pypickle def A(): return B() def B(): return -13 # pickle def B(): return 42 # pickle from pypickle import * try: from pickle import * except ImportError: pass If you import pickle and call pickle.A() you will get -13 which is not what you are after.
Maybe I've missed this and someone else already suggested it, but
couldn't we provide a (probably C-coded) function
replace_globals(module, globals)
that would, say, replace the
globals in _pypickle with the globals in pickle? Then you could write
something like::
from _pypickle import *
try:
from _pickle import *
module = __import__('_pickle')
except ImportError:
module = __import__('_pypickle')
replace_globals(module, globals())
Steve
I'm not in-sane. Indeed, I am so far out of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy
- Previous message: [Python-Dev] Choosing a best practice solution for Python/extension modules
- Next message: [Python-Dev] Choosing a best practice solution for Python/extension modules
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]