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/2004-July/046434.html below:

[Python-Dev] Fix import errors to have data

[Python-Dev] Fix import errors to have dataCharles Cazabon python at discworld.dyndns.org
Tue Jul 27 19:20:31 CEST 2004
Tim Peters <tim.peters at gmail.com> wrote:
> 
> Seems to me a module is present if and only if you try to import it,
> and the import succeeds, or the import fails and the module name is in
> sys.modules after.

This is a bit I've never been quite sure of.  If a module knows it imports
something not available everywhere, and can handle that bit missing, shouldn't
it already wrap its import of that module in a try: ... except ImportError:
block?

> >>> import pty  # exists, but is broken on Windows
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "C:\Program Files\Zope-2.7.2-0\bin\Lib\pty.py", line 19, in ?
>     import termios
> ImportError: No module named termios
> >>> 'pty' in sys.modules
> True

To me, it would seem more sensible (and would address the Windows brittleness
Tim mentions) if the above did /not/ leave pty in sys.modules -- i.e. the
import failed either completely, or not at all.  The above is a "partial
failure" which seems (to me) to be the root cause of the confusion.  Instead,
it should fail completely, and then the pty module can (if it wants) try to
import termios and handle it gracefully at that level if necessary.

Charles
-- 
-----------------------------------------------------------------------
Charles Cazabon                           <python at discworld.dyndns.org>
GPL'ed software available at:     http://www.qcc.ca/~charlesc/software/
-----------------------------------------------------------------------
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