I have a file called hotel_helper.py
from which I want to import a function called demo1
, but I am unable to import it.
My hotel_helper.py
file:
def demo1():
print('\n\n trying to import this function ')
My other file:
from hotel.helpers.hotel_helper import demo1
demo1()
but I get:
ImportError: cannot import name 'demo1' from 'hotel.helpers.hotel_helper'
When I import using from hotel.helpers.hotel_helper import *
instead of from hotel.helpers.hotel_helper import demo1
it works and the function gets called. I tried importing the whole file with from hotel.helpers import hotel_helper
and then call the function with hotel_helper.demo1()
and it works fine. I don't understand what's wrong in first method. I want to directly import function rather using *
or importing the whole file.