python - Importing python modules from another directory
问题描述
I am trying to import files (python files) from another directory but it is not working as I have tried.
/pythonproject
.main.py
.__init__.py
->folder1
->.file1.py
->.file2.py
->.__init__.py
->folder2
->.functions.py
->.globals.py
->.__init__.py
I am trying to import functions.py inside of my file2.py.
I have tried
from functions import *
import functions
#file2.py
sys.path.insert(0, '/pythonproject')
import functions
解决方案
我想你这个案子的朋友是sys.path.append
。
推荐阅读
- node.js - 为什么我不能在一个 post 请求中使用 res.json() 两次?
- arrays - 我可以确保 NVCC 已设法将数组放入寄存器中吗?
- javascript - 来自变量的函数参数作为字符串 javascript 失败
- spring - 如何在 Spring MVC 4 中启用 DEBUG 日志级别
- android - firebase 表列出所有用户
- django - Django:模型字段中的用户列表
- r - 更精确地在 r 中导入数据
- r - 从嵌套列表中进行有效抽样
- android - React Native 如何手动将 API 级别更改为 26
- python - 机器人唤醒时向所有用户发送消息