473,325 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Documentation on creating new types with slots in C ?

Hi all,

Of what I heard Python 2.3 now allow creation of new types in C with
slots.
Is there somewhere some documentation on this, or at least an example ?

Thanks a lot

Boris
Jul 18 '05 #1
7 1788
Boris Boutillier wrote:
Hi all,

Of what I heard Python 2.3 now allow creation of new types in C with
slots.
Is there somewhere some documentation on this, or at least an example ?


I'm not sure what you mean by "with slots" in this context. Creating
new types is well documented at:

http://www.python.org/doc/current/api/newTypes.html

and descriptors, assuming that might be what you mean by 'slots',
at http://users.rcn.com/python/download/Descriptor.htm (all the
examples there are in Python, but it should be easy for you to
translate them into C).
Alex

Jul 18 '05 #2
Alex Martelli <al***@aleax.it> writes:
Boris Boutillier wrote:
Hi all,

Of what I heard Python 2.3 now allow creation of new types in C with
slots.
Is there somewhere some documentation on this, or at least an example ?


I'm not sure what you mean by "with slots" in this context. Creating
new types is well documented at:

http://www.python.org/doc/current/api/newTypes.html

and descriptors, assuming that might be what you mean by 'slots',
at http://users.rcn.com/python/download/Descriptor.htm (all the
examples there are in Python, but it should be easy for you to
translate them into C).


I would guess he means this:

http://www.python.org/sf/696193

and I would also be interested in an example.

Thomas
Jul 18 '05 #3
Thomas Heller wrote:
...
Of what I heard Python 2.3 now allow creation of new types in C with
slots.
... I would guess he means this:

http://www.python.org/sf/696193
i.e. METAtypes (types whose instances are types) with '__slots__' ...?

and I would also be interested in an example.


Sorry, I've never written a metatype in C -- always in Python, almost
invariably inheriting from the built-in type.

"Normal" C types don't _need_ __slots__ of course, since __slots__'s
effect (avoiding a per-instance dict) is most easily achieved by
simply leaving the tp_dictoffset field at 0 (as most built-in types
do, save for those who DO want a per-instance dict -- functions and
modules come to mind).
Alex

Jul 18 '05 #4
That was not clear.
By slots, I mean the equivalent of '__slots__' in pure python,
ie adding some attribute as offsets at the end of the C description of a
Type.
And in fact what I am really looking for is how to describe '__slots__' in the C
description of a Metaclass.

Hope this make it a bit clearer.

Boris
On Fri, 17 Oct 2003 14:58:44 +0000, Alex Martelli wrote:
Boris Boutillier wrote:
Hi all,

Of what I heard Python 2.3 now allow creation of new types in C with
slots.
Is there somewhere some documentation on this, or at least an example ?


I'm not sure what you mean by "with slots" in this context. Creating
new types is well documented at:

http://www.python.org/doc/current/api/newTypes.html

and descriptors, assuming that might be what you mean by 'slots',
at http://users.rcn.com/python/download/Descriptor.htm (all the
examples there are in Python, but it should be easy for you to
translate them into C).
Alex


Jul 18 '05 #5
Thanks Thomas, I think this is exactly what I was looking for.

Boris

On Fri, 17 Oct 2003 17:20:49 +0200, Thomas Heller wrote:
Alex Martelli <al***@aleax.it> writes:
Boris Boutillier wrote:
Hi all,

Of what I heard Python 2.3 now allow creation of new types in C with
slots.
Is there somewhere some documentation on this, or at least an example ?


I'm not sure what you mean by "with slots" in this context. Creating
new types is well documented at:

http://www.python.org/doc/current/api/newTypes.html

and descriptors, assuming that might be what you mean by 'slots',
at http://users.rcn.com/python/download/Descriptor.htm (all the
examples there are in Python, but it should be easy for you to
translate them into C).


I would guess he means this:

http://www.python.org/sf/696193

and I would also be interested in an example.

Thomas


Jul 18 '05 #6
"Boris Boutillier" <bo**************@arteris.net> writes:
That was not clear.
By slots, I mean the equivalent of '__slots__' in pure python,
ie adding some attribute as offsets at the end of the C description of a
Type.
And in fact what I am really looking for is how to describe '__slots__' in the C
description of a Metaclass.


Either you or I are confused: do you want the slots to appear on the
*type* or on *instances of the type*?

Cheers,
mwh

--
In general, I'd recommend injecting LSD directly into your temples,
Syd-Barret-style, before mucking with Motif's resource framework.
The former has far lower odds of leading directly to terminal
insanity. -- Dan Martinez
Jul 18 '05 #7
[Thomas]
I would guess he means this:

http://www.python.org/sf/696193

and I would also be interested in an example.

[Boris] Thanks Thomas, I think this is exactly what I was looking for.


For an alternative, which also works on Python 2.2, you can take a look
into the sources for ctypes.

Thomas
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jacek Generowicz | last post by:
I am writing an extension type, and wish to add some magic methods which are not catered for by the tp_<whatever> slots (eg tp_init -> __init__) in PyTypeObject. My methods seem to work correctly...
3
by: mscir | last post by:
I'm trying to find thorough documentation for creating graphs using serverside Excel from ASP. Any book recommendations? A well-documented COM wrapper would be nice if it allowed us to create...
24
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When...
97
by: Cameron Laird | last post by:
QOTW: "Python makes it easy to implement algorithms." - casevh "Most of the discussion of immutables here seems to be caused by newcomers wanting to copy an idiom from another language which...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.