Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Clearly the answer is a .clone() or .copy() method...

if you want Python to smell like Java or Ruby. :->



http://docs.python.org/library/copy.html

Seems to disagree with you.


That's a module in the standard library.

What I'm saying is, there's no copy or clone or dup method built into Python's base object, as there is in Ruby. And Python programmers are not instructed to define a clone method for a class, as in Java. A __copy__ or __deepcopy__, okay, but not copy or deepcopy.

Hence, in Python you just don't see foo.clone() or foo.dup() or foo.copy() or foo.deepcopy(). Instead, you see copy.copy(foo) or copy.deepcopy(foo). Pythonic code often looks different than Ruby or Java, looks more stand-alone function-y than instance method-y.


By putting it in a module, you avoid having to add the method to every single class.


By putting it on Object (this is my ruby side speaking) you avoid the same thing.


Hmm, no. You have to add __copy__ and/or __deepcopy__ to every class.


Only to override the default implementation.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: