I'm assuming they are functionally the same, bar some negligible under-the-hood differences. If so, which form is more Pythonic?
The x.y
form makes it implicit that packages and modules are involved, and should be the preferred form when that is the case.
If t
is a symbol defined in module y
, then:
>>> from x.y import t as z
>>>
...but!
>>> import x.y.t as z
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named t
>>>
The dot notation is reserved for modules, and should be used when modules are involved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With