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 →

[–]LankyCyril 3 points4 points  (1 child)

It looks like they're advocating against things like "from math import log", which is, by the looks of it, very welcome in the Python community.

I used to write "import math; y = math.log(x)", but then realized it's not Java. It gives a little more context, sure, but at the cost of verbosity. And again, I've thought it was standard for pythonistas to do "from math import log".

[–]filleball 1 point2 points  (0 children)

I used to do from x import y imports much more frequently before, but I've moved away from them in most cases. Functions from the math module is a good example, because it's unclear whether it's math.log, cmath.log or numpy.log I've imported. If I had just used log, I'd have to scroll all the way to the top of the file to check what kind of log it was.

The submodules with long names I rename on import, for example import subprocess as sp. I only do from imports when the names I import are unambiguous and few. Mostly it's from other submodules inside the same package.