Use global, or not

Michael Torrie torriem at gmail.com
Sat Jun 29 22:54:48 EDT 2019


On 06/29/2019 05:42 AM, Cecil Westerhof wrote:
> That was the other possibility I was thinking about. And that would be
> maybe better. Because I now do things like:
>     global_dict['messages']['created'].format(len(filepathArr))
> 
> much better would be:
>     instance.created(len(filepathArr))

Sure. But if you put all your globals in a class, you're most likely
only ever going to instantiate it once, so it's really a singleton. And
the standard Python implementation of a singleton is usually a module.
So just create a file called globals.py and place all your globals in
there. Then import it into each module that needs it and refer to it as
globals.whatever.  This is what I do and I've seen others do this also.
So it must be right! haha.





More information about the Python-list mailing list