在Azure函数中导入Python文件

发布于 2025-01-24 06:32:03 字数 181 浏览 2 评论 0原文

我确实在类似的结构中导入了Azure函数中的文件

from folder1.folder.script import function

,但它向我显示了错误 异常:modulenotfounderror:

当我在Azure函数外尝试时,NO模块名为“ folder1”。

I did import a file in azure function in a structure like this

from folder1.folder.script import function

but it showed me error
Exception: ModuleNotFoundError: No module named 'folder1'

whene I tried outside the azure function it worked so any idea why it's can't be accessed within the function

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罪歌 2025-01-31 06:32:03

创建一个文件夹calcFunction并添加了add_number函数

def  add_number(n1,n2):
sum = n1 + n2;
return  sum;
print("The sum of two number is",sum)

从Azure函数Python class class

import  logging
import  azure.functions  as  func

from calcfunction import  calc

def  main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')

id = req.params.get('id')

if  not  id:
try:
req_body = req.get_json()
except  ValueError:
pass
else:
id = req_body.get('id')

if  id:
return  func.HttpResponse(f"This is the user entered userId {id} and calc function value {calc.add_number(12,24)}")

else:
return  func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a ID in the query string or in the request body for a personalized response.",
status_code=200
)

我的azure函数项目文件夹结构和结果

Created a Folder calcfunction and added the add_number function:

def  add_number(n1,n2):
sum = n1 + n2;
return  sum;
print("The sum of two number is",sum)

Calling this method from Azure Function Python Class:

import  logging
import  azure.functions  as  func

from calcfunction import  calc

def  main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')

id = req.params.get('id')

if  not  id:
try:
req_body = req.get_json()
except  ValueError:
pass
else:
id = req_body.get('id')

if  id:
return  func.HttpResponse(f"This is the user entered userId {id} and calc function value {calc.add_number(12,24)}")

else:
return  func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a ID in the query string or in the request body for a personalized response.",
status_code=200
)

My Azure Functions Project Folder Structure and the result:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文