0

I know what it does, how it works and all, but why might we ever want to use it?

I mean if a programmer wanted to import the objects from a module, he could then just use the simple

import <module>

syntax. It's not like the all variable is hiding anything, right?

1

1 Answer 1

2

from <module> import * and help(<module>) both use the __all__ attribute of a module to limit what is imported or documented.

Note that from <module> import * is generally considered bad practice unless you are building a central API for a package with the implementation dispersed over various contained modules.

Sign up to request clarification or add additional context in comments.

3 Comments

OK, I am just a novice Python programmer, so I didn't get any of the last sentence, but again, how is it limiting anything? You can still get the objects you want without any trouble.
@AkshatTripathi: It is not intended to limit what is accessible. It is only limiting what automated tools will use. from <module> import * would import all global names otherwise, including other modules imported into <module>. This is usually not what you want.
OK, I got it now. Thanks. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.