I am unable to import my other python file in the init.py file. I have tried importing that according to the same way as mentioned in the documentation.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python#import-behavior
This is my init.py file:
    import logging
    import azure.functions as func
    from . import test
    def main(req: func.HttpRequest) -> func.HttpResponse:
        logging.info('Python HTTP trigger function processed a request.')
        print("test")
        num = sum_num(2, 3)
        print(num)
        name = req.params.get('name')
        if not name:
            try:
                req_body = req.get_json()
            except ValueError:
                pass
            else:
                name = req_body.get('name')
        if name:
            return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
        else:
            return func.HttpResponse(
                "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
                status_code=200
            )
this is my test.py file with very basic sum function:
    def sum_num(val1, val2):
        print("inside function")
        return val1 + val2
Please help me out how to import this sum_num function in my init.py file.
the folder structure is also fine as you can see:
Error i am getting in the logs
You have already imported the module using
from . import test
so in order to access the function from the module you should use
num = test.sum_num(2, 3)
Alternatively you can import only the function from the module.
from .test import sum_num
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With