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

[Python-Dev] More joy with test_strptime

[Python-Dev] More joy with test_strptime [Python-Dev] More joy with test_strptimeTim Peters tim.peters at gmail.com
Tue Jul 13 07:33:18 CEST 2004
[Brett]
> OK, so the question becomes how can I have test_site (which I will fix
> with your suggestions for the removal of existing files and directories;
> when I rewrote that chunk of code I had EAFP on the brain) test to make
> sure that a module is imported?

By making sure the module it imports isn't in sys.modules before it
tries to import it.  Beforehand:

    old_version = sys.modules.get(self.imported)
    if old_version is not None:
        del sys.modules[self.imported]

Then make sure the .pth file puts self.imported back in sys.modules.

At the end,

    del sys.modules[self.imported]
    if old_version is not None:
        sys.modules[self.imported] = old_version
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