[Python-Dev] Change PEP 399 import recommendation

Stefan Behnel stefan_ml at behnel.de
Sun Oct 13 10:18:49 CEST 2013


Antoine Pitrou, 12.10.2013 23:40:
> On Sat, 12 Oct 2013 23:35:23 +0200
> Christian Heimes wrote:
>> A directory with pure Python modules is less cumbersome than a couple
>> of facade modules or intended code in try/except ImportError blocks.
> 
> I don't find it cumbersome to be explicit here. It makes it obvious
> what happens. It also makes it extra easy to import the pure Python if
> desired (for example for unit tests, or for benchmarking).

I agree. I find it much easier to read a plain and obvious

    try:
       from _cmodule import *
    except ImportError:
       from _pymodule import *

in a facade module than

    # lots and lots
    # of unused
    # Python code
    # here ...

    # ... and then this, well hidden at the end, telling
    # me that I just waded through the entirely wrong code:

    try:
       from _cmodule import *
    except ImportError:
       pass

As I said, that's different for the case where the C module replaces only a
somewhat small part of the Python code, but for the case of an (almost)
complete replacement, I would like to see the 3-files approach as the One
Way To Do It.

Stefan




More information about the Python-Dev mailing list