vendredi 14 juin 2019

is possible to have a global variable only in module scope without use global?

i have a module

#FactoryModule.py:
x=1
class Method1:
   def __init__(self):
          global x
          x=5
class Method2:
   def __init__(self):
          global x
          x=6

class Factory:
     def __init__(self):
          global x
          x=4

In this manner i set value at same variable!

I can do this also with a Singleton but Singleton use same memory also if i call this FactoryModule.py in another file i have this equal instance.

How to obtain a Singleton only in Module Scope?

tks

Aucun commentaire:

Enregistrer un commentaire