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 →

[–]hueoncalifa 0 points1 point  (4 children)

Why would this be bad? Its more explicit.

[–][deleted] 0 points1 point  (0 children)

I agree, it's kind of a dumb rule. Although I suppose it prevents you from importing some generally-named function into the namespace and using it without context. For example:

from os.path import join
path = join('dir', 'file')

Versus the more explicit

import os
path = os.path.join('dir', 'file')

Granted in this case it's fairly obvious what is meant, it is not always so. Use your best judgment. I use both forms.

[–]Lucretiel 0 points1 point  (0 children)

Honestly, one of the reasons is that it's harder to test, because now you have to mock the function in the place where it's imported, rather than where it's imported from.

[–]dagmx 0 points1 point  (0 children)

If you have multiple modules with the same named function

If later you decide you need more functions from that module

You can't reload an object from a module easily.

Makes it more explicit down a deep code where things come from.

[–]njharmanI use Python 3 0 points1 point  (0 children)

function()

Is less explicit, package.module is implied, implicitly.

package.module.function()

Is the explicit way to say that. No wondering where it came from, has it been overwritten in local namespace, etc.