0

I have a few objects, that should have shared fields. Some of them may be strings or other immutables. How can I share them in the best way? My only variant is to write a container manually.

class Shared(object):
    def __init__(self, what_to_share):
        self.inner_value = what_to_share    

    @property
    def value(self):
        return self.inner_value

    @value.setter
    def value(self, new_value):
       self.inner_value = new_value
Felix
  • 3,351
  • 6
  • 40
  • 68
  • 1
    What does 'share' mean? Who/what will have access to the objects? Do you want mutable strings? – User Apr 20 '14 at 10:30
  • Just here and now I have one object, that fills a buffer, and second object, that should read it, activated by third object's call. In C++ I knew, that even the "=" assignment does not change the object's address, but in Python even some string operations do it. – Felix Apr 20 '14 at 10:40
  • Do you combine python and C++ or C? This should be mentioned in the tags then. Have a look at the differences between mutable and immutable datatypes. Example: http://stackoverflow.com/questions/8056130/immutable-vs-mutable-types-python – User Apr 20 '14 at 10:44
  • No, this current project is in Python only. – Felix Apr 20 '14 at 10:45

0 Answers0