Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81284
| Path | csiph.com!usenet.pasdenom.info!news.etla.org!feeder.erje.net!eu.feeder.erje.net!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@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; 'skip:[ 20': 0.04; 'anyway.': 0.05; 'interpreter': 0.05; 'subject:Python': 0.06; '(b)': 0.07; '*not*': 0.07; 'failing': 0.07; 'ignored': 0.07; 'modifying': 0.07; 'pypi': 0.07; 'python3': 0.07; 'suppose': 0.07; 'sys': 0.07; '22,': 0.09; 'global,': 0.09; 'imported': 0.09; 'os.path': 0.09; 'sys,': 0.09; 'wrong,': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'language,': 0.12; "(i'm": 0.16; 'afterwards.': 0.16; 'believes': 0.16; 'both)': 0.16; 'empty.': 0.16; 'encodings,': 0.16; 'fiddle': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'keyed': 0.16; 'modules.': 0.16; 'path:': 0.16; 'paths.': 0.16; 'per-module': 0.16; 'resolved?': 0.16; 'subject:dependencies': 0.16; 'subject:import': 0.16; 'sys.modules': 0.16; 'sys.path': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'first.': 0.19; 'properly': 0.19; "python's": 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; '(a)': 0.24; 'entries': 0.24; 'module,': 0.24; 'replace': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'first,': 0.26; 'references': 0.26; 'skip:" 30': 0.26; 'second': 0.26; 'supported': 0.26; 'header:In-Reply-To:1': 0.27; 'possibility': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; "d'aprano": 0.31; 'idea,': 0.31; 'implicit': 0.31; 'loading': 0.31; 'object.': 0.31; 'os,': 0.31; 'steven': 0.31; 'though.': 0.31; 'anyone': 0.31; 'file': 0.32; 'probably': 0.32; 'running': 0.33; 'guess': 0.33; 'skip:_ 10': 0.34; 'maybe': 0.34; 'subject:the': 0.34; "i'd": 0.34; 'could': 0.34; "can't": 0.35; 'skip:u 20': 0.35; 'something': 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'doubt': 0.36; 'instances': 0.36; 'library.': 0.36; 'maintained': 0.36; 'module.': 0.36; 'processed': 0.36; "i'll": 0.36; 'possible': 0.36; 'should': 0.36; 'wrong': 0.37; 'turn': 0.37; 'two': 0.37; 'being': 0.38; 'minimum': 0.38; 'nov': 0.38; 'skip:[ 10': 0.38; 'pm,': 0.38; 'track': 0.38; 'previous': 0.38; 'rather': 0.38; 'that,': 0.38; 'does': 0.39; 'aside': 0.39; 'itself': 0.39; 'though,': 0.39; 'sure': 0.39; 'either': 0.39; 'how': 0.40; 'even': 0.60; 'ian': 0.60; 'subject:"': 0.60; "you're": 0.61; 'name': 0.63; 'soon': 0.63; 'face': 0.64; 'more': 0.64; 'different': 0.65; 'useful.': 0.68; 'default': 0.69; 'qualified': 0.72; "how's": 0.74; 'obvious': 0.74; 'present.': 0.74; 'belief': 0.84; 'belief,': 0.84; 'cheating': 0.84; 'concept.': 0.84; 'horrible': 0.84; 'instantly': 0.84; "it'd": 0.84; 'presumably': 0.84; 'subject:history': 0.84; 'thing).': 0.84; 'to:none': 0.92; 'rick': 0.93; 'contrary': 0.95 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=bWM4BYDKBK0/DJ6JSF4k10Gp6wqJhFQytZXlC5YsbZA=; b=H5hgJZaYqlnynEm4435siHxaUJ/PLi7ixAAGhPmrT/ugebs0S9Enw0U2HB24n8GU2r QhCgZyEvc+RbIzjVJGSir8LTYiffz945dMLg1fx6uNSdDztXdwoR0V9zkLqqd23kHcIi abA15+x5BiKbknLzavwB4KJye44UvH66htOnsNhZRs0/+CMTId/2ufDAH55X8uF+Qn7D oKXUGP0vho9qBZRREMS13VRFFfGbGPMDKchzHDiz/CYYAlft8Sgvf08IW5xmK22NrImO BpLeIFbkc6fPzBy5Qv2P2Wpt1Zl7uTx0oDqa6zgfAi+njdbc1yXU0q53hbaRp3LP+/Lg j95g== |
| MIME-Version | 1.0 |
| X-Received | by 10.107.134.39 with SMTP id i39mr9191905iod.53.1416661234718; Sat, 22 Nov 2014 05:00:34 -0800 (PST) |
| In-Reply-To | <547080a0$0$12981$c3e8da3$5496439d@news.astraweb.com> |
| References | <066c46c8-a04d-4489-b15a-b603c1b1818b@googlegroups.com> <m4m04r$aeg$1@dont-email.me> <8661e407-4472-4208-97c2-f666f6502c67@googlegroups.com> <mailman.16104.1416584077.18130.python-list@python.org> <547080a0$0$12981$c3e8da3$5496439d@news.astraweb.com> |
| Date | Sun, 23 Nov 2014 00:00:34 +1100 |
| Subject | Re: PyWart: "Python's import statement and the history of external dependencies" |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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 | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16139.1416661237.18130.python-list@python.org> (permalink) |
| Lines | 115 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1416661237 news.xs4all.nl 2888 [2001:888:2000:d::a6]:58000 |
| X-Complaints-To | abuse@xs4all.nl |
| X-Received-Bytes | 9713 |
| X-Received-Body-CRC | 3149448054 |
| Xref | csiph.com comp.lang.python:81284 |
Show key headers only | View raw
On Sat, Nov 22, 2014 at 11:25 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Ian Kelly wrote:
>
> - It's hard to keep track of what modules are in the standard library. Which
> of the following is *not* in Python 3.3's std lib? No cheating by looking
> them up.)
>
> os2emxpath, wave, sndheader, statslib, poplist, plist,
> pickletools, picklelib, path, cgi, cgitb, copylib, xpath
Okay, here's my guesses.
os2emxpath: In the stdlib, but more often accessed as "os.path" while
running under OS/2
wave: Not in the stdlib, though I'd avoid the name anyway.
sndheader: Not in the stdlib - probably on PyPI though
poplist, plist, pickletools, picklelib: I suspect PyPI, not stdlib,
but could be wrong
path: Not in the stdlib (there's os.path and I doubt there'd be both)
cgi, cgitb: In the stdlib
copylib: No idea, could be either way.
xpath: I'll guess this as not being present.
I'm probably pretty wrong, though.
>>> # Contrary to popular belief, sys.path is *NOT* a module, #
>>> # no, it's a global! #
>>
>> I really doubt that this is a popular belief.
>
> I'm not aware of anyone who believes that sys.path is a module.
> But yes, sys.path is not just global, but process-wide global. *All* modules
> share the same sys.path.
Even leaving aside Rick's sloppy language, I still doubt that it's
popular belief that sys.path be module-specific. You're modifying
something in a different module, and Python's always maintained that
two instances of "import sys" will give two references to the exact
same module object.
> That would be horrible. But here's an alternative which is less horrible and
> maybe even useful.
>
> There's still a single process-wide search path, but there's a second
> per-module search path which is searched first. By default it's empty.
>
> So a module can define it's own extra search path:
>
> __path__ = ['look/here', 'and/here']
> import something
>
> without affecting any other modules.
That's what Rick said first, and then said that if you're going to be
explicit, you should do the job properly and not have _any_ implicit
paths.
Thing is, though, it still breaks the sys.modules concept. Either
__path__ is ignored if the module was found in sys.modules, or it's
possible to have multiple entries with the same name (which would make
it hard to have a module replace itself in sys.modules, currently a
supported thing). Although I suppose all it'd require is that
sys.modules be keyed by __file__ rather than __name__, so they're
identified by fully qualified path and file name. (What does that do
in the face of .pyc files?)
>> And after all that, it would still fail if you happened to want to
>> import both "calendar" modules into the same module.
>
> __path__ = []
> import calendar
> __path__ = ['my/python/modules']
> import calendar as mycalendar
Frankly, if you actually want this, I think it's time to turn to an
uglier-but-more-flexible method.like poking around in importlib. (I'm
not sure off-hand how you'd go about it, it's not instantly obvious
from help(importlib).) I'm more concerned about the possibility of
your import succeeding or failing depending on the order of other
imports:
# foo.py
import calendar
# bar.py
__path__ = ['my/python/modules']
import foo
import calendar
How's that one to be resolved? That's what I don't like.
So long as sys.modules is (a) process-wide and (b) keyed by module
name rather than file name, sys.path MUST be process-wide too, and
MUST be set on startup, or as soon as possible afterwards. Any module
imported prior to altering sys.path will be fetched based on the
previous search path - and you have to import sys to change sys.path,
which means the minimum set of unalterable modules is, on Python 3.5:
rosuav@sikorsky:~$ cat showmods.py
import sys
print(", ".join(sorted(sys.modules.keys())))
rosuav@sikorsky:~$ python3 showmods.py
__main__, _codecs, _collections_abc, _frozen_importlib, _imp, _io,
_signal, _sitebuiltins, _stat, _sysconfigdata, _thread, _warnings,
_weakref, _weakrefset, abc, builtins, codecs, encodings,
encodings.aliases, encodings.latin_1, encodings.utf_8, errno,
genericpath, io, marshal, os, os.path, posix, posixpath, site, stat,
sys, sysconfig, zipimport
... that's a decent lot of modules you can't fiddle with. Hence
PYTHONPATH, which presumably is processed by the interpreter prior to
loading any modules.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
PyWart: "Python's import statement and the history of external dependencies" Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-15 21:01 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Chris Angelico <rosuav@gmail.com> - 2014-11-16 16:16 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" alex23 <wuwei23@gmail.com> - 2014-11-21 10:14 +1000
Re: PyWart: "Python's import statement and the history of external dependencies" Chris Angelico <rosuav@gmail.com> - 2014-11-21 11:31 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-20 19:53 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Tim Chase <python.list@tim.thechases.com> - 2014-11-21 04:26 -0600
Re: PyWart: "Python's import statement and the history of external dependencies" Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-21 07:52 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Tim Chase <python.list@tim.thechases.com> - 2014-11-21 10:12 -0600
Re: PyWart: "Python's import statement and the history of external dependencies" Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-21 10:42 -0700
Re: PyWart: "Python's import statement and the history of external dependencies" Ned Batchelder <ned@nedbatchelder.com> - 2014-11-21 06:32 -0500
Re: PyWart: "Python's import statement and the history of external dependencies" Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-21 08:33 -0700
Re: PyWart: "Python's import statement and the history of external dependencies" Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-21 10:24 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Chris Angelico <rosuav@gmail.com> - 2014-11-22 05:34 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Michael Torrie <torriem@gmail.com> - 2014-11-21 12:05 -0700
Re: PyWart: "Python's import statement and the history of external dependencies" Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-21 12:29 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Michael Torrie <torriem@gmail.com> - 2014-11-21 15:54 -0700
Re: PyWart: "Python's import statement and the history of external dependencies" Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-21 12:23 -0700
Re: PyWart: "Python's import statement and the history of external dependencies" Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-21 14:25 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-21 15:21 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Chris Angelico <rosuav@gmail.com> - 2014-11-22 10:52 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-21 17:07 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Chris Angelico <rosuav@gmail.com> - 2014-11-22 13:36 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-22 02:27 -0700
Re: PyWart: "Python's import statement and the history of external dependencies" sohcahtoa82@gmail.com - 2014-11-21 16:33 -0800
Import a module from a specific file path (was: PyWart: "Python's import statement and the history of external dependencies") Ben Finney <ben+python@benfinney.id.au> - 2014-11-22 11:37 +1100
Re: Import a module from a specific file path Marko Rauhamaa <marko@pacujo.net> - 2014-11-22 08:28 +0200
Re: Import a module from a specific file path (was: PyWart: "Python's import statement and the history of external dependencies") Chris Angelico <rosuav@gmail.com> - 2014-11-22 13:32 +1100
Re: Import a module from a specific file path Ben Finney <ben+python@benfinney.id.au> - 2014-11-22 17:46 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-21 17:32 -0700
Re: PyWart: "Python's import statement and the history of external dependencies" Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-21 17:48 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-21 15:38 -0500
Re: PyWart: "Python's import statement and the history of external dependencies" Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-22 23:25 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Chris Angelico <rosuav@gmail.com> - 2014-11-23 00:00 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-23 17:30 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Rustom Mody <rustompmody@gmail.com> - 2014-11-22 22:44 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Chris Angelico <rosuav@gmail.com> - 2014-11-23 17:56 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Chris Angelico <rosuav@gmail.com> - 2014-11-23 17:59 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-24 11:37 +1300
Re: PyWart: "Python's import statement and the history of external dependencies" Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-23 22:25 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Chris Angelico <rosuav@gmail.com> - 2014-11-24 17:34 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-24 10:34 +0000
Re: PyWart: "Python's import statement and the history of external dependencies" Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-24 08:51 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Ned Batchelder <ned@nedbatchelder.com> - 2014-11-24 12:06 -0500
Re: PyWart: "Python's import statement and the history of external dependencies" Robin Becker <robin@reportlab.com> - 2014-11-24 17:07 +0000
Re: PyWart: "Python's import statement and the history of external dependencies" Marko Rauhamaa <marko@pacujo.net> - 2014-11-24 19:08 +0200
Re: PyWart: "Python's import statement and the history of external dependencies" Rustom Mody <rustompmody@gmail.com> - 2014-11-24 09:38 -0800
Re: PyWart: "Python's import statement and the history of external dependencies" Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-24 15:34 -0700
Re: PyWart: "Python's import statement and the history of external dependencies" Ben Finney <ben+python@benfinney.id.au> - 2014-11-23 18:43 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Chris Angelico <rosuav@gmail.com> - 2014-11-23 18:51 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-23 11:23 -0500
Re: PyWart: "Python's import statement and the history of external dependencies" Chris Angelico <rosuav@gmail.com> - 2014-11-24 03:36 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Tim Chase <python.list@tim.thechases.com> - 2014-11-22 15:27 -0600
Re: PyWart: "Python's import statement and the history of external dependencies" Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-23 12:00 +1100
Re: PyWart: "Python's import statement and the history of external dependencies" Tim Chase <python.list@tim.thechases.com> - 2014-11-22 19:33 -0600
csiph-web