Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38648
| Path | csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <isaac.to@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; 'skip:` 10': 0.05; 'sys': 0.05; 'assign': 0.07; 'rename': 0.07; 'python': 0.09; '(without': 0.09; 'expected.': 0.09; 'fails.': 0.09; 'filesystem': 0.09; 'happen?': 0.09; '2.7': 0.13; 'resulting': 0.13; '(say': 0.16; '3.2,': 0.16; 'assigns': 0.16; 'variable.': 0.16; 'work.\xa0': 0.16; 'package.': 0.17; 'saying': 0.18; 'load': 0.19; 'module': 0.19; 'import': 0.21; 'work.': 0.23; 'statement': 0.23; 'seems': 0.23; 'tried': 0.25; 'skip:" 20': 0.26; 'used,': 0.27; 'module.': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'behavior.': 0.29; 'skip:& 10': 0.29; 'probably': 0.29; 'knows': 0.30; 'skip:& 30': 0.30; 'code': 0.31; 'file': 0.32; 'instead,': 0.33; 'anyone': 0.33; 'to:addr:python-list': 0.33; 'skip:& 20': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'there': 0.35; 'really': 0.36; 'except': 0.36; 'but': 0.36; 'loaded': 0.36; 'modules': 0.36; 'correctly': 0.37; 'why': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'copying': 0.38; 'files': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'first': 0.61; 'natural': 0.65; 'results': 0.65; 'subject:Import': 0.84; 'suboptimal.': 0.84; 'affected.': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=9wooS1ut0ZVbyy79CKrTCrWE8q3kzdK8OVjj0jiic9U=; b=ejVq5KTMq+El8RErFsJXO44boeQ1LsB9Ve96709rDcpdgJJh5d8Oe+1Ng/K/K0ldR0 F2HYMryEWVlvGwqxgVT5pYmSS4Cg+efKE/k9qLWApcJhhWP5UgeyXnik3cV3wUWRO3wF 0vDvRONAYQNMJnqltEVslBih3PDapoFCPmp3gYziHzOLgUimlLo/lw2W6gFw+pb1Ifz/ Jicc4rRZnS9/h1L1ijxwp4iB4P7hLOOAnMjGYcTxur4QGu2Igm/xrl1cuXxauZ05Z8Jb a8pYwWQdqHrvmci7JYCqGIlNqFOXV7yqs+k2Mr1NoIoLdqSzwsGcD+jofojbpZv5kAsu oEkg== |
| MIME-Version | 1.0 |
| X-Received | by 10.229.106.134 with SMTP id x6mr1182981qco.132.1360565436132; Sun, 10 Feb 2013 22:50:36 -0800 (PST) |
| Date | Mon, 11 Feb 2013 14:50:36 +0800 |
| Subject | Import redirects |
| From | Isaac To <isaac.to@gmail.com> |
| To | python-list@python.org |
| Content-Type | multipart/alternative; boundary=002354332a3a83af7d04d56d5373 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1627.1360565439.2939.python-list@python.org> (permalink) |
| Lines | 70 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1360565439 news.xs4all.nl 6865 [2001:888:2000:d::a6]:46529 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:38648 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
I have a package (say "foo") that I want to rename (say, to "bar"), and for
compatibility reasons I want to be able to use the old package name to
refer to the new package. Copying files or using filesystem symlinks is
probably not the way to go, since that means any object in the modules of
the package would be duplicated, changing one will not cause the other to
be updated. Instead, I tried the following as the content of
`foo/__init__.py`:
import sys
import bar
sys.modules['foo'] = bar
To my surprise, it seems to work. If I `import foo` now, the above will
cause "bar" to be loaded and be used, which is expected. But even if I
`import foo.baz` now (without first `import foo`), it will now correctly
import "bar.baz" in its place.
Except one thing: it doesn't really work. If I `import foo.baz.mymod` now,
and if in "bar.baz.mymod" there is a statement `import bar.baz.depmod`,
then it fails. It correctly load the file "bar/baz/depmod.py", and it
assigns the resulting module to the package object bar.baz as the "depmod"
variable. But it fails to assign the module object of "mymod" into the
"bar.baz" module. So after `import foo.baz.mymod`, `foo.baz.mymod` results
in an AttributeError saying 'module' object has no attribute 'mymod'. The
natural `import bar.baz.mymod` is not affected.
I tested it with both Python 2.7 and Python 3.2, and I see exactly the same
behavior.
Anyone knows why that happen? My current work-around is to use the above
code only for modules and not for packages, which is suboptimal. Anyone
knows a better work-around?
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Import redirects Isaac To <isaac.to@gmail.com> - 2013-02-11 14:50 +0800
csiph-web