En Fri, 28 Aug 2009 21:47:51 -0300, Chris Rebert <c...@rebertia.com> escribió:
On Fri, Aug 28, 2009 at 11:38 AM, xiaosong xia<xiaosong...@yahoo.com> wrote:

2. How to make a copy constructor?

Since Python lacks overloading based on parameter types, generally one
does it the other way around and instead provides a method that
produces a copy of the object. For example:

class Point(object):
    def __init__(self, x, y):
        self. x = x
        self.y = y

    def copy(self):
        return Point(self.x, self.y)

For simple enough cases, the copy and deepcopy functions in the copy module are just fine:
http://docs.python.org/library/copy.html

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to