Last active
August 29, 2015 14:02
-
-
Save smbanaie/a9d0e091f331061e5fd5 to your computer and use it in GitHub Desktop.
Python Global Variable - Singelton Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mojtaba: | |
SharedVariable = {} | |
def __init__(self): | |
self.MyDict = self.SharedVariable | |
if __name__=='__main__': | |
a = Mojtaba() | |
b = Mojtaba() | |
user1 = {} | |
user1["fn"] = "ali" | |
user1["ln"] = "alavi" | |
a.MyDict[0] = user1 | |
print "a >> " | |
print a.MyDict | |
print "b >>" | |
print b.MyDict | |
user2={} | |
user2["fn"] = "ali" | |
user2["ln"] = "alavi" | |
b.MyDict[1] = user2 | |
print "a >> " | |
print a.MyDict | |
print "b >>" | |
print b.MyDict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment