擅长:python、mysql、java
<p>也许我把你的问题简单化了,因为你把你的第一个例子简单化了,但我同意一些评论者的观点,并建议你改变你的存储方式。<strong>存储列表,根据需要生成字符串。</strong></p>
<pre><code>In [1]: class C(object):
...: def __init__(self, values):
...: self.values = values.split(' - ')
...: @property
...: def value_str(self):
...: return ' - '.join(self.values)
...:
In [2]: c = C('one - two - three')
In [3]: c.values
Out[3]: ['one', 'two', 'three']
In [4]: c.values.append('four')
In [5]: c.value_str
Out[5]: 'one - two - three - four'
</code></pre>