4 ms·
> Clearly the answer is a .clone() or .copy() method... if you want Python to smell like Java or Ruby. :->
by ewiethoff 18y ago
> Clearly the answer is a .clone() or .copy() method...
if you want Python to smell like Java or Ruby. :->
- latortuga 18y agohttp://docs.python.org/library/copy.html http://docs.python.org/library/copy.html Seems to disagree with you.
- ewiethoff 18y agoThat'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.
- bdr 18y agoBy putting it in a module, you avoid having to add the method to every single class.