Polymorphic copy: Difference between revisions

Content added Content deleted
(started ruby)
Line 264: Line 264:
</python>
</python>


In this example we use the ''cPickle'' module which is an implementation of the pickle features coded in C for optimal performance. We import it as ''pickle'' since we intending only on using those features which are common to both implementations. (The pure Python implementation is retained for those who which to create their own classes derived therefrom). The ''dumps()'' and ''loads()'' methods dump the data structures to a string and load them from a string, respectively. (The more common use of ''pickle'' is to serialize the data out to a file or over a network connection).
In this example we use the ''cPickle'' module which is an implementation of the pickle features coded in C for optimal performance. We import it as ''pickle'' since we intend to use only those features which are common to both implementations. (The pure Python implementation is retained for those who which to create their own classes derived therefrom). The ''dumps()'' and ''loads()'' methods dump the data structures to a string and load them from a string, respectively. (The more common use of ''pickle'' is to serialize the data out to a file or over a network connection using file-like ''.read()'' and ''.write()'' methods. For those we'd use the ''pickle.dump()'' and ''pickle.load()'' methods).


For the simplest cases one can use simple Python introspection to copy simple objects:
For the simplest cases one can use simple Python introspection to copy simple objects: