A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-February/086356.html below:

[Python-Dev] Choosing a best practice solution for Python/extension modules

[Python-Dev] Choosing a best practice solution for Python/extension modulesSteven Bethard steven.bethard at gmail.com
Sun Feb 22 19:16:18 CET 2009
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
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4