Globals or objects? (is: module as singleton)

James Newton jnewton at
Thu Feb 21 18:03:25 CET 2008

Duncan Booth wrote: 
> you can create additional module instances (by calling new.module)

Hi Duncan,

Could you provide a scenario where this would be useful (and the best

> What you get with a module is support for locating a specific module
> and ensuring that you don't get duplicate copies of a named module.

So if I were to execute the following pseudo-code, the second 'import'
would simply point at the module (instance) imported the first time:

import mymodule
changeContentsOf("") #on the hard disk
import mymodule

The values, functions and classes available in mymodule would only
change if I were to restart the application.

> Regarding your question about saving the values: what you would
> usually do would be to store the values in a separate configuration
> file and the module would load them on startup and then rewrite the
> configuration file when you call a save function...

That's what I would normally do, too.

Thanks for your help,


More information about the Python-list mailing list