does the order in which the modules are placed in a file matters ?

Chris Angelico rosuav at gmail.com
Wed Dec 16 11:49:18 EST 2015


On Thu, Dec 17, 2015 at 3:42 AM, Dan Strohl <D.Strohl at f5.com> wrote:
> For the general modules it doesn't matter, however using if you are using any non-standard packages, and If there are duplicate names in any of the modules and if you import them with a "*" (as some packages suggest), it can cause you to end up referring to an object you were not intending to.
>
> [chomp]
>
> Note, using * is dis-recommended, though pretty often done, for more information on using *, see: https://docs.python.org/2/tutorial/modules.html#importing-from-a-package

This is exactly why (well, one of the reasons why) star imports are
generally not recommended. There are a small number of modules that
have promised to keep their namespaces clean in order to make this
viable, but even there, it has issues of confusion. There are a few
good places to use star imports, such as when you wrap one module in
another; I would STRONGLY recommend against using two star imports in
a single file, without being VERY sure of what you're doing.

ChrisA



More information about the Python-list mailing list