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/2003-December/041017.html below:

[Python-Dev] Re: Christmas Wishlist

[Python-Dev] Re: Christmas Wishlist [Python-Dev] Re: Christmas WishlistGuido van Rossum guido at python.org
Mon Dec 15 13:38:01 EST 2003
> I've seen a couple people get bitten by the fact that a module gets 
> loaded twice if there are separate local & global imports for it:
> 
>      % mkdir pkg
> 
>      % touch pkg/__init__.py
> 
>      % cat >pkg/a.py
>      print 'A is being imported (not re-used)'
>      class A: pass
> 
>      % cat >pkg/b.py
>      from a import A as LocalA
>      from pkg.a import A as GlobalA
>      print isinstance(LocalA(), GlobalA)
>      print isinstance(GlobalA(), LocalA)
> 
>      % PYTHONPATH=.; python pkg/b.py
>      A is being imported (not re-used)
>      A is being imported (not re-used)
>      0
>      0
> 
> Since pkg/a gets loaded twice, we end up with two versions of class A, 
> which are not compatible.  In practice this usually comes up if a 
> package uses local imports between submodules, and then an outside user 
> uses a global import to get a submodule.

That's actually a slightly different problem; sys.path should not
include any directories that are also packages on other directories in
sys.path.

--Guido van Rossum (home page: http://www.python.org/~guido/)

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