python-3.x - 在 Azure 函数中使用类和外部 py 文件
问题描述
我正在使用 HTTP 触发器模板处理 Azure Functions。
我正在尝试调用另一个文件中的类,但是当我运行代码时,控制台会显示一个错误:
这是我拥有的代码:
我在文档中搜索,但我没有发现任何关于此的内容。我可以做些什么来处理我的文件和他们的类?
谢谢 :)
解决方案
If you want to import custom class in Azure Function, we should use explicit relative or absolute references. At the moment, Azure function doesn't support implicit relative imports of the form import xxx
from within the project. For more details, please refer to the document
For example
__app__
is the function application's top level module and can be used as an anchor for performing absolute imports.
__app__
Function1
__init__.py
func_module.py
HelperCode
__init__.py
helper_module.py
we can use the following sytaxes (as examples):
from __app__ import HelperCode
from __app__.HelperCode import helper_module
import __app__.Function1
import __app__.HelperCode
推荐阅读
- amazon-web-services - How to view the ec2 instance limits on aws
- python-3.x - 如何对 csv 文件中的一行或一列的值求和?
- r - 数值积分和优化 R 的问题
- python - 如何以最快的方式对填充有列表的数组(大 N)进行排序?
- java - 正则表达式在Java中的括号内获取字符串?(包括括号内的另一个括号)
- sequence-diagram - 如何增加 ZenUML 序列图中参与者之间的空间?
- jquery - 在循环内更改多个下拉列表值
- laravel - 将 laravel 表单更改为 html 表单
- angular - 如何使用 ng2-stompjs 向许多订阅者广播消息?
- google-cloud-messaging - 在 GCM 弃用后,我能否获得新的 GCM 令牌?