"from module import data; print(data)" vs "import module; print(module.data)"

Ethan Furman ethan at stoneleaf.us
Thu Feb 25 11:35:52 EST 2016

On 02/24/2016 07:39 PM, Steven D'Aprano wrote:

> (2) import module
> (a) Mutation is no different from (1)(a) above. No change.
> (b) Rebinding `module.data = []` affects the imported module, and therefore
> everything that relies on it.

More accurate: and therefore everything that has not already done a 
`from module import data` as those will be unaffected by the rebinding.


More information about the Python-list mailing list