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:
- Rename your custom package
- 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.
精彩评论