python根据操作系统类型调用特定模块

if LINUX:
    from . import _pslinux as _psplatform
elif WINDOWS:
    from . import _pswindows as _psplatform
else:  # pragma: no cover
    raise NotImplementedError('platform %s is not supported' % sys.platform)

以上代码写在该库的__init__.py中,该入口向外提供功能api。其中_pslinux是一个名为_pslinux.py的文件模块,针对linux,_pswindows 则是_pswindows.py,针对Windows。二者都实现了__init__中的接口,但是内部是针对不同os的具体实现细节。__init__根据os的类型,选择性加载不同实现。

猜你喜欢

转载自www.cnblogs.com/thingk/p/12975387.html