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 Answers1

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 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. – Akshat Tripathi Aug 31 '13 at 08:47
  • 1
    @AkshatTripathi: It is not intended to limit what is accessible. It is only limiting what automated tools will use. `from import *` would import **all** global names otherwise, including other modules imported into ``. This is usually not what you want. – Martijn Pieters Aug 31 '13 at 08:49
  • OK, I got it now. Thanks. :) – Akshat Tripathi Aug 31 '13 at 08:50