Home

En Wed, 01 Aug 2007 20:14:06 -0300, Raj B <rajb@rice.edu> escribió:

> Consider a new-style class
>
> class rabbit(object):
> def __init__(self,c):
> self.color = c
>
> r1=rabbit("blue")
> r2=rabbit("purple")
>
> Which C struct in the Python implementation is used to represent the
> instances c1 and c2 of the
> new-style class? I understand that when the class 'rabbit' is
> created, the type_new function
> in typeobject.c creates a copy of a 'struct typeobject' with
> dictionary tp_dict appropriately modified.

Yes. Then, rabbit("blue") means "call rabbit with a single argument,
blue". The slot tp_call is searched, giving usually type_call, which
itself calls tp_new (type_new if not overriden). (see type_call in
typeobject.c).

> However, I can't figure out which structure is used for new-style
> instances and where the instance dictionary is stored. Could anyone
> please clarify?

All objects in Python are based on a PyObject structure; see object.h
Different object types have additional fields at the end, but all share
the same basic layout.

--
Gabriel Genellina

previous
next

Re: What Are These Import/From Statements about?
Re: XML Processing
Re: Find Out How the Neocons Staged a Terror Attack That Killed Thousands of Americans on 9/11
Re: (curses) issue about inch()
Re: Is it possible to delete an element from a sorted array with O(1) time?
tanie meble katowice
ecommerce
piła spalinowa
quick cash loans
zaproszenia ślubne