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.py44 chars2 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.py27 chars2 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.
gistlibby LogSnag