Skip to content Skip to sidebar Skip to footer

Is It Always A Good Idea To Import Very Specifically In Python?

This is pretty much Python, but asking from a Django user. Suppose this is how Django apps are layout: Webclient apps myapp#1 library library.py myapp#2 views.py m

Solution 1:

You should always import names from where they're defined. That way if webclient.apps.myapp.library should stop importing LibraryClass one day, you won't break the other imports.

Solution 2:

As a follow-up to Ignacio's answer, you should look at the documentation of the libraries you are using, to see where it suggests you import things. It may be that although LibraryClass is defined in webclient.apps.myapp.library.library, it is documented as being in webclient.apps.myapp.library, so at some point, it the definition might be moved there, or webclient.apps.myapp.library.oldversion, but still accessible from webclient.apps.myapp.library.

Post a Comment for "Is It Always A Good Idea To Import Very Specifically In Python?"