Overcoming Python's limitations regarding instance methods

后端 未结 3 1548
孤城傲影
孤城傲影 2020-12-18 00:37

It seems that Python has some limitations regarding instance methods.

  1. Instance methods can\'t be copied.
  2. Instance methods can\'t be pickled.
3条回答
  •  無奈伤痛
    2020-12-18 01:27

    REST - Representation State Transfer. Just send state, not methods.

    To transfer an object X from A to B, we do this.

    1. A encode the state of X in some handy, easy-to-parse notation. JSON is popular.

    2. A sends the JSON text to B.

    3. B decodes the state of X form JSON notation, reconstructing X.

    B must have the class definitions for X's class for this to work. B must have all functions and other class definitions on which X's class depends. In short, both A and B have all the definitions. Only a representation of the object's state gets moved around.

    See any article on REST.

    http://en.wikipedia.org/wiki/Representational_State_Transfer

    http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

提交回复
热议问题