开发者

PyCharm module name conflicts

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜