** * This article is from Udemy "[Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style](https://www.udemy.com/course/python-beginner/" Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style ")" It is a class notebook for myself after taking the course of. It is open to the public with permission from the instructor Jun Sakai. ** **
Prepare directories and files like this.
lesson_package
└ talk
├ __init__.py
└ human.py
lesson.py
human.py
def sing():
return 'sing'
def cry():
return 'cry'
lesson.py
from lesson_package.talk import human
print(human.sing())
result
sing
By connecting with .
, you can import from the lower directory.
lesson_package
└ talk
├ __init__.py
└ human.py
└ tools
├ __init__.py
└ utils.py
lesson.py
human.py
from lesson_package.tools import utils #Absolute path
from ..tools import utils #Relative path
def sing():
return 'sing'
def cry():
return 'cry'
The relative path .
means "go up one layer".
Recommended Posts