Search code examples
pythonazureazure-function-app

How can I import my class in an Azure function app?


Hello guys i can't import my module in my function app, i read that i can't use from myclass import Class, so how i can import my class in my code? Test in azure portal give me cannot find module named....

This is my package explore

I have to add the classes in book,categore,user and databaseManager, how i should import it? I tried with from app.notify-user-function import book,user,category,databaseManager, but don't work.


Solution

  • You can try this:

    from relative path import class name
    

    For example:

    If you want to import Book in book.py, below is code in book.py

    class Book():
        def __init__(self, name):
            self.name = name
    
        def bark(self):
            print(self.name + " is barking.")
    

    you need to do this in __init__.py

    from .book import Book