Mauricio
Mauricio

Reputation: 742

How to simplify my imports

In my project each class is a file and my directory structure like this:

main.py
myGui/
    __init__.py (empty)
    ClassA.py
    ClassB.py

To use my classes In main.py I need import with:

from myGui.ClassA import ClassA
from myGui.ClassB import ClassB

How to import with:

from myGui import ClassA, ClassB

Upvotes: 3

Views: 1570

Answers (2)

Vardd
Vardd

Reputation: 1087

Assuming you added them to your __ init__.py,

from . import ClassA, ClassB

Should work.

Upvotes: 0

user4600699
user4600699

Reputation: 1485

You can add this into your __init__.py

from .ClassA import ClassA
from .ClassB import ClassB

And then import them like you mentioned

Upvotes: 4

Related Questions