VSCode项目目录包路径问题备忘
VSCode项目目录包路径问题备忘
在linux服务器上
# 返回当前工作目录
# /home/kmax
os.getcwd()
# 该变量是一个字符串列表,用于确定解释器的模块搜索路径
# [‘/home/kmax/my_base_1’, ‘/home/kmax’, ‘/usr/lib/python3.6’…]
sys.path
有关项目目录,有层级关系的,参见:
https://docs.python.org/release/3.6.9/tutorial/modules.html#packages
sound/ Top-level package
__init__.py Initialize the sound package
formats/ Subpackage for file format conversions
__init__.py
wavread.py
wavwrite.py
aiffread.py
aiffwrite.py
auread.py
auwrite.py
…
effects/ Subpackage for sound effects
__init__.py
echo.py
surround.py
reverse.py
…
filters/ Subpackage for filters
__init__.py
equalizer.py
vocoder.py
karaoke.py
…
When importing the package, Python searches through the directories on sys.path looking for the package subdirectory.
import the desired function or variable directly:
from sound.effects.echo import echofilter
echofilter(input, output, delay=0.7, atten=4)
from package import item
The import statement first tests whether the item is defined in the package;
if not, it assumes it is a module and attempts to load it.