python - How do relative imports work? -
i have directory structure this
project/ __init__.py greetings.py script.py
greetings.py
def hello(): print('hello')
script.py
from . import greetings greetings.hello()
when execute python script.py
following error occurs
traceback (most recent call last): file "script.py", line 1, in <module> . import greetings importerror: cannot import name 'greetings'
if use import greetings
in script.py
works. why relative import give error? , why work when use from . import models
in views while working in django.
please follow module vs package concept in python.
here created package have import package as:-
from project import greetings
Comments
Post a Comment