On Wed, Jun 10, 2009 at 4:56 PM, Kevin Teague <ke...@bud.ca> wrote:

>
> __dict__ is an attribute of every Python object. It's typically only
> an internal detail, and generally not accessed directly. One area
> where __dict__ modification would differ from attribute access is with
> an attribute that's a property. Modifying the __dict__ would ignore
> the property getter/setter code, where as modifying the attribute will
> still invoke those methods. In other words, __dict__ manipulation
> breaks encapsulation ... although in rare cases this is what you want
> to do!
>
>
> >>> class Foo(object): pass
> ...
> >>> f = Foo()
> >>> f.__dict__
> {}
> >>> f.cat = 'dog'
> >>> f.__dict__
> {'cat': 'dog'}
> >>> f.__dict__['cow'] = 'moo'
> >>> f.cow
> 'moo'
>
>
> >
>
Technically it's not on every Python object, any object that defines
__slots__ won't have it.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to