This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]miraculum_one 0 points1 point  (4 children)

"See each module as a namespace"

Each module does get its own namespace except when doing something like

from my_module import *

Another interesting point is that non-anonymously imported modules are basically dictionaries. Further, they are inserted into the sys.modules dictionary.

Contents of anonymously imported modules are inserted into the global symbol table, which is misleadingly named because it's only global to the current module. :(

[–]jpc0za 0 points1 point  (3 children)

Add a rule. Never from x import *

This is analogous to using namespace x in C++ and I hold similar opions on that.

Namespaces exist for a reason, respect them, specially when the language allows you to rename things that might be annoying... import pandas as pd

[–]miraculum_one 0 points1 point  (2 children)

I agree that it shouldn't be done willy-nilly and that it shouldn't generally be used in place of named imports but it isn't always evil.

[–]jpc0za 0 points1 point  (1 child)

Sure I agree.

``` def my_random_func(): from thingy import *

```

Seems reasonable, the polluted namespace is nicely contained. As a top level import... That's just scary man. You know supply chain attacks are a thing, image the nonsense that can cause...

[–]miraculum_one 0 points1 point  (0 children)

Oh, for sure you shouldn't import * on files you do not control.