__new__() does not return anything, on singletong pattern

Mario Figueiredo marfig at gmail.com
Thu Mar 12 04:46:45 EDT 2015


On Thu, 12 Mar 2015 21:38:00 +1300, Gregory Ewing
<greg.ewing at canterbury.ac.nz> wrote:

>
>I would just provide a function:
>
>_map = None
>
>def get_map():
>    global _map
>    if _map is None:
>       _map = Map()
>    return _map
>
>and document the fact that you shouldn't call Map()
>directly.

Oh, you are so right! Been so long since I last created a singleton I
forgot all about the idiomatic approaches to the pattern.

Thanks Greg. That is much, much, better.



More information about the Python-list mailing list