這是可能的嗎?Python 2.7 - 如何將一個Class屬性(指針?)指定給一個變量(需要創建Oz-esque數據流變量)
這個想法是,我想有一個特殊的變量,在分配或獲取其值時做一些處理。我也希望它看起來像一個常規變量,所以點符號在這裏是一個問題。
我知道這不是很明確,但這正是我需要試圖複製Oz-esque Dataflow Variables。
如果像這些類型的數據流變量已經在python庫中實現,請告訴我。
例子:
class Promise(object):
def __init__(self):
self._value = 'defalt_value'
@property
def value(self):
#some processing/logic here
return self._value
@value.setter
def value(self, value):
#some processing/logic here
self._value = value
my_promise_obj = Promise()
my_promise = my_promise_obj.value
my_promise = 'Please, set my_promise_obj.value to this string'
print ('Object`s Value: ' + my_promise_obj.value)
print ('My Variable`s value: ' + my_promise)
print ('Has I changed the class attr?: ' + str(my_promise == my_promise_obj))