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/046430.html below:

[Python-Dev] Fix import errors to have data

[Python-Dev] Fix import errors to have data [Python-Dev] Fix import errors to have dataTim Peters tim.peters at gmail.com
Tue Jul 27 18:59:35 CEST 2004
[Jim Fulton]
> ...
> No.  I'm proposing a way for a Python developer to detect the
> presence or absence of a module.

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.

>>> import cupcake  # no such thing
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named cupcake
>>> 'cupcake' in sys.modules
False
>>> 

>>> 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
>>>

Not that I like this -- it turns broken modules into "a feature".  A
function that answered the question directly would be mounds better.
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