import two classes from another file in python

To import two classes from another file in Python, you can use the from keyword followed by the file name, import keyword, and class names separated by commas. Here's an example:

main.py
from example_file import MyClass1, MyClass2
44 chars
2 lines

In this example, we import MyClass1 and MyClass2 from the file named example_file.py.

You can also import all classes in the file by using an asterisk *:

main.py
from example_file import *
27 chars
2 lines

However, it's generally not recommended because it can lead to naming conflicts and make code harder to understand. It's a better practice to import only the specific classes you need.

related categories

gistlibby LogSnag