Recently, an issue with the Python import
statements struck me.
Problem: I have a package say foo
containing a module bar
which I need to refer as spams
.
There are 2 ways I can perform this operation:
Method-01: import foo.bar as spams
Method-02: from foo import bar as spams
The first method is what I generally use and the alternate method is what I discovered. But I realised that the 2nd method is a bit more "explicit".
I would like to know what are the differences between the two methods(if any) with regards to:
- Efficiency
- Pythonic code
- Convention