Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #85423

Re: Weird behavior on __dict__ attr

Date 2015-02-09 22:12 -0500
From Dave Angel <davea@davea.name>
Subject Re: Weird behavior on __dict__ attr
References <20150210025243.GB1266@FuzzyHorror>
Newsgroups comp.lang.python
Message-ID <mailman.18591.1423537938.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 02/09/2015 09:52 PM, Shiyao Ma wrote:
> Hi.
>
> My context is a little hard to reproduce.

WHY don't you try?  Telling us about a class without showing how it's 
defined leaves us all guessing.

Start by telling us Python version.  And if it's 2.x, tell us whether 
this class is an old style or new style class.

>
> NS3 is a network simulation tool written in C++. I am using its Python binding.
>
> So the class I am dealing with is from a .so file.
>
> Say, I do the following:
>
> %
>
> import ns.network.Node as Node
>
> # Node is a class
> # it has a __dict__ attr
>
> # Now I instantiate an instance of Node
> n = Node()
>
> # I checked, there is no __dict__ on 'n'
> # but the following succeeds.
>
> n.foobar = 3
>
>
>
> My understanding is the foobar is stored in n.__dict__, but seemingly n has no __dict__.
>
> So where does the foobar go?
>

Lots of possibilities.  Simplest is slots.  if you define __slots__, 
then there's no dictionary in each instance.

https://docs.python.org/3.4/reference/datamodel.html#slots

-- 
DaveA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Weird behavior on __dict__ attr Dave Angel <davea@davea.name> - 2015-02-09 22:12 -0500

csiph-web