On 4/24/07, Ketan Joshi <[EMAIL PROTECTED]> wrote:

> If so, why isn't this function defined as:
>
> def copy(self):
>     import copy
>     return copy.copy(self)

The if-case in your code makes sure that the property __class__ is of
UserDict-inheritance. I believe it's there in case of multiple
classes.

class Gas:
  def __init__(self):
    pass
class Oil:
  def __init__(self):
    self.foo = Gas()
    self.dict = UserDict()

b = Oil()

b.__class__ will be __main__.Oil, and if you pass the entire class
around and want a copy of the dict-property, the copy()-method in
UserDict will first it is a UserDict-instance before copying it. If it
isn't, it creates one out of the existing data.


-- 
- Rikard - http://bos.hack.org/cv/
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to