Skip to content

Instantly share code, notes, and snippets.

@KVInventoR
Created November 27, 2016 19:14
Show Gist options
  • Save KVInventoR/331ead03a8355f93d33de714ebdfab6b to your computer and use it in GitHub Desktop.
Save KVInventoR/331ead03a8355f93d33de714ebdfab6b to your computer and use it in GitHub Desktop.
Конкретно нужно чтобы были созданы 2 экземпляра класса в которых была бы общая переменная т.е. изменив значение атрибута в одном экземпляре в другом оно бы тоже поменялось...?
class Foo:
some = 0
@classmethod
def setSome(cls, val):
cls.some = val
@classmethod
def getSome(cls):
return cls.some
f1 = Foo()
f2 = Foo()
print(f1.getSome(), f2.getSome())
f1.setSome(5)
print(f1.getSome(), f2.getSome())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment