Home >Backend Development >Python Tutorial >How to Import Python Classes from the Same Directory or Subdirectory?
Importing Classes from the Same Directory or Subdirectory
Importing Python classes from within the same directory or subdirectory can be achieved using the following methods:
Importing from the Same Directory
from user import User from dir import Dir
Importing from a Subdirectory
from classes.user import User from classes.dir import Dir
In Python 3, another option for importing from the same directory is to prefix the module name with a dot:
from .user import User from .dir import Dir
The above is the detailed content of How to Import Python Classes from the Same Directory or Subdirectory?. For more information, please follow other related articles on the PHP Chinese website!