Add path to sys.path vs. PEP E402

谁说我不能喝 提交于 2019-12-06 02:44:23

You could put the sys.path extension in a separate module, e.g. _paths.py.

Contents of _paths.py:

import sys

sys.path.append(some_module_path)
sys.path.append(some_other_module_path)
# ...and so on...

And then in your main application:

import sys

import _paths
import some_module

some_module.some_func()

This solution puts your "project configuration" nicely in a single place (which makes it easy to maintain in the future), and complies with at least PEP8 (including E402) and pylint rules.

I know this doesn't answer the question, but it may be helpful information.

You can import that module by directly specifying its path, without using sys.path.append

In Python 3 this is as simple as

import imp
some_module = imp.load_source('some_module', '/path/to/some_module.py')

More information here: How to import a module given the full path?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!