How to import standard library module instead of local directory?

前端 未结 3 1364
醉话见心
醉话见心 2021-02-20 14:43

I have a local directory named \"calendar\" with an \"__init__.py\" file.

I want \"import calendar\" to import the standard library module calendar, and not the module d

3条回答
  •  无人共我
    2021-02-20 15:39

    You could modify sys.path, import the package, then restore sys.path to its original value.

    import sys
    original_path = sys.path
    sys.path = original_path[1:]
    import calendar
    sys.path = original_path
    

提交回复
热议问题