我有以下文件夹结构.
application/app/folder/file.py
我想从另一个驻留的Python文件中的file.py中导入一些函数
application/app2/some_folder/some_file.py
我试过了
from application.app.folder.file import func_name
和其他一些尝试,但到目前为止我无法正确导入.我怎样才能做到这一点?
我有一个 Python 项目的文件夹结构,如下所示:
proj/
??? cars
? ??? honda.py
? ??? volvo.py
??? trucks
? ??? chevy.py
? ??? ford.py
??? main.py
??? params.py
Run Code Online (Sandbox Code Playgroud)
内容params.py:
""" Parameters used by other files. """
serial = '12-411-7843'
Run Code Online (Sandbox Code Playgroud)
内容honda.py:
""" Information about Honda car. """
from params import serial
year = 1988
s = serial
print('year is', year)
print('serial is', s)
Run Code Online (Sandbox Code Playgroud)
在proj/文件夹中,我可以使用 iPython 运行脚本:
$ cd path/to/proj/
$ ipython
In [1]: run cars/honda.py
year is 1988
serial …Run Code Online (Sandbox Code Playgroud)