Why is `using Module` used in Julia while `from module import *` is generally discouraged in Python?



There’s probably a subtle difference in the functionality but to me using Module in Julia and from module import * in Python accomplish basically the same thing. In Python wildcard imports are discouraged [PEP8]; PEP8 states:

Wildcard imports (from import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools

Wouldn’t the same rationale apply to Julia code? I don’t see anything in the Julia Style Guide that provides any guidance on this. A properly-configured IDE can of course show you where a symbol in a given source file comes from, but that’s true in both languages as well.


There are two issues with from foo import * in Python:

  1. It makes it hard to figure out where the imported names came from
  2. It can potentially clobber existing names in your module or names from other modules you’ve imported

Issue (1) does apply, as you’ve noted, in Julia, but issue (2) does not. Doing using Foo will not clobber any of your existing types or functions (it will just require you to be specific and refer to any conflicting types as Foo.MyType instead of just MyType). For that reason, using Foo is less harmful than from foo import * in Python.

But I do agree that the convenience of using Foo should be balanced against the increased difficulty in reasoning about a piece of code. I generally try to avoid multiple plain using declarations in a given module, and instead try to prefer using Foo: my_method when I only need one or two names from a given module.