"from x import y as z" vs. "import xy as z"

I assume that they are functionally the same, let's say a few minor differences under the hood. If so, which form is more Pythonic?

+4
source share
1 answer

The xy form implies that packages and modules are involved and should be the preferred form when this is.

If t is the character defined in y , then:

 >>> from xy import t as z >>> 

... but

 >>> import xyt as z Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named t >>> 

Point notation is reserved for modules and should be used when modules are involved.

+3
source

Source: https://habr.com/ru/post/1340163/


All Articles