Skip to content Skip to sidebar Skip to footer

Python Import Vs From...import

Why do I have to do: from entertainment_website.models import Event instead of import entertainment_website.models.Event The 2nd one I get: ImportError: No module named Event

Solution 1:

Because Event seems to not be an importable module / namespace but a class that is part of the former.


Solution 2:

Event is not a module, it's a class (well, I'm assuming a class by the naming convention).


Solution 3:

In Python, the first one imports the class from a module. The second one imports a MODULE not a class.


Post a Comment for "Python Import Vs From...import"