我是 python 新手,正在使用 CherryPy Web Server 和 Jinja 2 模板引擎开发我的第一个 python 应用程序。
我正在使用 Velleman K8055 USB 实验板,它有一个我正在导入的 python 模块。
为了使 K8055 正常运行,我必须在 K8055 模块中创建一个类的实例,然后打开与板的连接……据我了解,我必须保持该连接/实例运行,并使用该唯一控制板的实例,甚至从子模块中。
我很难弄清楚如何从我的子模块/包中访问先前初始化的 K8055 实例......
我有一个与以下非常相似的应用程序结构......
SmartyPi/
SmartyPi/smartypi.py
SmartyPi/smartypi/__init__.py
SmartyPi/smartypi/scheduler/
SmartyPi/smartypi/scheduler/__init__.py
SmartyPi/smartypi/scheduler/Scheduler.py
SmartyPi/smartypi/web/
SmartyPi/smartypi/web/__init__.py
SmartyPi/smartypi/web/k8055.py
SmartyPi/smartypi/web/root.py
SmartyPi/smartypi/web/schedule.py
在“SmartyPi/smartypi.py”中,我初始化了我的 k8055 对象实例:
from pyk8055 import k8055
k = k8055(0)
我希望能够从以下位置访问相同的“k”实例:
SmartyPi/smartypi/web/k8055.py
SmartyPi/smartypi/web/schedule.py
我个人似乎无法弄清楚...
“SmartyPi/smartypi.py”不是创建我的 K8055 实例的最佳位置吗?
我应该在其他地方制作它,我怎样才能根据需要完成这项工作?