官术网_书友最值得收藏!

Package search paths

Typically, Python searches for modules in some specific system paths. You can print these paths by importing the sys module and printing the sys.path. This will actually return the strings inside the PYTHONPATH environment variable and inside the operating system; notice the result is just a normal Python list. You can add more paths to the search scope using a list function such as insert().

However, it's better to install the packages in the default search paths so the code won't break when you share it with other developers:

A simple package structure with a single module will be something like this:


The __init__ file inside each package (in the global directory or in the sub-directory) will tell the Python interpreter that this directory is a Python package, and each file ending with .py will be a module file, which could be imported inside your code. The second function of the init file is to execute any code inside it once the package is imported. However, most developers leave it empty and just use it to mark the directory as a Python package.

主站蜘蛛池模板: 娱乐| 皮山县| 岗巴县| 宁乡县| 长顺县| 邳州市| 宣化县| 蛟河市| 建宁县| 兴业县| 台东县| 额尔古纳市| 比如县| 建平县| 南安市| 洛阳市| 仙游县| 邵东县| 白水县| 甘洛县| 崇信县| 贵阳市| 唐山市| 唐海县| 红原县| 池州市| 句容市| 玛纳斯县| 左云县| 富平县| 巴南区| 蒙阴县| 吕梁市| 环江| 蓬溪县| 德令哈市| 贺州市| 财经| 福贡县| 满洲里市| 连州市|