Open odscjames opened 6 years ago
In the case of os
, I prefer A.
If it would be something else like datetime
I would prefer:
from datetime import datetime (or any other)
instead of
import datetime
and then having to do datetime.datetime
Is there some rules you have for when you prefer A or B?
I've just found issues with circular imports when using type B and now I think I need to go and read up more on how Python imports work, as I'm clearly missing some details!
This gist might help https://gist.github.com/datagrok/40bf84d5870c41a77dc6 In terms of style you can also read Pep8 https://www.python.org/dev/peps/pep-0008/#imports
That's an interesting read, thanks!
As far as I can tell, PEP8 doesn't cover my original question. There is a section on "When importing a class from a class-containing module, ...." that touches on this, but it doesn't actually express a preference!
A)
B)
Discuss!
I think I prefer A? It makes it clearer when reading code what is being called, without having to check the imports, which might be a long way away from the code.
I don't think PEP8 covers this? (It says prefer on separate lines, prefer absolute imports where possible, and no wild card (*) imports).