0

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

Yafaa
  • 307
  • 1
  • 14
  • Is `script` the file name? to import function from another folder/directory, this code works: `from application.app.folder.file import func_name` –  Apr 25 '22 at 10:59

1 Answers1

2

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