Importing from a relative path in Python
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a folder for my client code, a folder for my server code, and a folder for code that is shared between them Proj/ Client/ Client.py Server/ Server.py Common/ __init__.py Common.py How do I import Common.py from Server.py and Client.py? 回答1: Don't do relative import. From PEP8 : Relative imports for intra-package imports are highly discouraged. Put all your code into one super package (i.e. "myapp") and use subpackages for client, server and common code. Update: " Python 2.6 and 3.x supports proper relative imports (...) ". See Dave's