开发者

PyCharm module name conflicts

开发者 https://www.devze.com 2023-02-17 12:23 出处:网络
I have a module named \'io\' in my package: mypackage.io. This causes a conflict with the Python built-in io package. Thus, whenever I use PyCharm to perform debugging of my code, since pydev helper u

I have a module named 'io' in my package: mypackage.io. This causes a conflict with the Python built-in io package. Thus, whenever I use PyCharm to perform debugging of my code, since pydev helper uses gzip (which in turns uses io), I encounter a module ImportError. The problem is partly due to PyCharm automatically add my package path to the interpreter path. So I am left with two options

  • From the answer of Trying to import module with the same name as a built-in mo开发者_运维技巧dule causes an import error, it seems that I need to make changes to gzip.py so that it will import io by absolute importing.
  • Rename my module from io to something_else

Am I missing a better solution?


You basically have two options:

  1. Rename your custom package
  2. Explicitly use mypackage.io.foo instead of io.foo

Generally speaking, its bad form to map a custom package atop a built-in unless you are intentionally changing that default builtin's behavior. Any short-term game will be offset by many, long-term headaches.

0

精彩评论

暂无评论...
验证码 换一张
取 消