Jump to content

Polymorphic copy: Difference between revisions

(started ruby)
Line 264:
</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 intendingintend onlyto onuse usingonly 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:
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.