Categories
Python Answers

How to import the class within the same directory or sub directory with Python?

Spread the love

Sometimes, we want to import the class within the same directory or sub directory with Python.

In this article, we’ll look at how to import the class within the same directory or sub directory with Python.

How to import the class within the same directory or sub directory with Python?

To import the class within the same directory or sub directory with Python, we can import as a relative or absolute import.

For instance, we write

from .user import User

to import the User class from the user module same directory as the current script.

Conclusion

To import the class within the same directory or sub directory with Python, we can import as a relative or absolute import.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *