Mailing List Archive

Creating a new type with an extension module
Is there any documentation anywhere on how to go about writing an
extension which implements a new type? The extending/embedding
tutorial give me, very quickly and painlessly, a module with
functions, but I could really do with them being object methods.
http://www.python.org/doc/current/api/newTypes.html is unhelpful
in the extreme -- do I have to resort to reading source?

--
\S -- siona@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
| If music be the food of love, bring me a doggie bag.
Creating a new type with an extension module [ In reply to ]
In article <Ctp*vl52n@news.chiark.greenend.org.uk>,
Sion Arrowsmith <siona@chiark.greenend.org.uk> wrote:
> Is there any documentation anywhere on how to go about writing an
> extension which implements a new type? The extending/embedding
> tutorial give me, very quickly and painlessly, a module with
> functions, but I could really do with them being object methods.
> http://www.python.org/doc/current/api/newTypes.html is unhelpful
> in the extreme -- do I have to resort to reading source?

I am not sure if this is what you are after, but I have found XXMODULE.C
+ XXOBJECT.C very helpful as small examples. I was able to easily turn
them into what I wanted.

--
Uwe Zessin


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Creating a new type with an extension module [ In reply to ]
[Sion Arrowsmith]
> Is there any documentation anywhere on how to go about writing an
> extension which implements a new type? The extending/embedding
> tutorial give me, very quickly and painlessly, a module with
> functions, but I could really do with them being object methods.
> http://www.python.org/doc/current/api/newTypes.html is unhelpful
> in the extreme

Everything important is there -- it's just missing all the words <wink>.

> -- do I have to resort to reading source?

Better, copy the source for some existing type and edit it. The
implementations of the builtin types are in the source distribution's
Objects directory; e.g., floatobject.c implements Python floats, and
listobject.c implements (no, I'm not telling <wink>). Browse those to get a
feel for it, then look at xxobject.c. That's a skeleton object
implementation you can start from.

the-source-is-documentation-too-&-even-better-you-can-compile-it-ly
y'rs - tim
Creating a new type with an extension module [ In reply to ]
In article <Ctp*vl52n@news.chiark.greenend.org.uk>,
Sion Arrowsmith <siona@chiark.greenend.org.uk> wrote:
>http://www.python.org/doc/current/api/newTypes.html is unhelpful
>in the extreme -- do I have to resort to reading source?

It appears that I do, but thanks to everyone who pointed me in
the direction of suitably readable source. I've got what I
wanted working -- it would just be nice to understand why it
works....

--
\S -- siona@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
| If music be the food of love, bring me a doggie bag.
Creating a new type with an extension module [ In reply to ]
Sion Arrowsmith <siona@chiark.greenend.org.uk> wrote:
: In article <Ctp*vl52n@news.chiark.greenend.org.uk>,
: Sion Arrowsmith <siona@chiark.greenend.org.uk> wrote:
:>http://www.python.org/doc/current/api/newTypes.html is unhelpful
:>in the extreme -- do I have to resort to reading source?

: It appears that I do, but thanks to everyone who pointed me in
: the direction of suitably readable source. I've got what I
: wanted working -- it would just be nice to understand why it
: works....

Mark Lutz's _Programming Python_ book explains this quite well (I still
use these parts today in fact). He has two chapters on embedding and
extending Python.

But the documentation on extending Python is pretty well known
deficiency. Luckily it is far easier than most languages, both to
accomplish and to understand (yet more kudos to Guido). Actually, in
responce to your earlier posting, I started writing a _SHORT_ webpage
explaining what is needed, which I hope to have available later today.
I plan (and hope) to make it into a How-To later.

-Arcege
Creating a new type with an extension module [ In reply to ]
Michael P. Reilly writes:
> But the documentation on extending Python is pretty well known
> deficiency. Luckily it is far easier than most languages, both to
> accomplish and to understand (yet more kudos to Guido). Actually, in
> responce to your earlier posting, I started writing a _SHORT_ webpage
> explaining what is needed, which I hope to have available later today.
> I plan (and hope) to make it into a How-To later.

If you'd like to make it a patch to the standard documentation, I'm
sure many people would be incredible grateful, including myself. The
time I have available to extend the documentation in all the ways that
are requested seems a bit fleeting at the moment.
Seriously, if anyone would like to extend the standard documents,
I'll be glad to lend a hand with the markup. If you write the
content, I'll accept it as text if I need to!


-Fred

--
Fred L. Drake, Jr. <fdrake@acm.org>
Corporation for National Research Initiatives
Creating a new type with an extension module [ In reply to ]
Fred L. Drake <fdrake@cnri.reston.va.us> wrote:

: Michael P. Reilly writes:
: > But the documentation on extending Python is pretty well known
: > deficiency. Luckily it is far easier than most languages, both to
: > accomplish and to understand (yet more kudos to Guido). Actually, in
: > responce to your earlier posting, I started writing a _SHORT_ webpage
: > explaining what is needed, which I hope to have available later today.
: > I plan (and hope) to make it into a How-To later.

: If you'd like to make it a patch to the standard documentation, I'm
: sure many people would be incredible grateful, including myself. The
: time I have available to extend the documentation in all the ways that
: are requested seems a bit fleeting at the moment.
: Seriously, if anyone would like to extend the standard documents,
: I'll be glad to lend a hand with the markup. If you write the
: content, I'll accept it as text if I need to!

I can do that, Fred. I like the Python Tex style, but I do have
problems making the necessary DVIs from your tools. I may need your
help on that (sun-i386-solaris). I do have to download your newest
version tho.

First things first: get the little HTML ref kit out. :)

-Arcege
Creating a new type with an extension module [ In reply to ]
Michael P. Reilly <arcege@shore.net> wrote:

: But the documentation on extending Python is pretty well known
: deficiency. Luckily it is far easier than most languages, both to
: accomplish and to understand (yet more kudos to Guido). Actually, in
: responce to your earlier posting, I started writing a _SHORT_ webpage
: explaining what is needed, which I hope to have available later today.
: I plan (and hope) to make it into a How-To later.

I've put a copy of my short, quick tutorial on how to write an
extension. It is very terse, but has all the basics, including a full
example, hints and some minor tricks.

http://starship.python.net/crew/arcege/extwriting/pyext.html

Let me know how well it reads (I doubt it reads well since it was
started this morning).

-Arcege
Creating a new type with an extension module [ In reply to ]
In article <faSb3.968$7X1.247240@news.shore.net>,
Michael P. Reilly <arcege@shore.net> wrote:
> http://starship.python.net/crew/arcege/extwriting/pyext.html
>
>Let me know how well it reads (I doubt it reads well since it was
>started this morning).

It's a lot more readable than just source code, and a lot more
informative with respect to the type and method structures. Any
chance of you borrowing Guido's time machine so I can read it
48 hours ago?

--
\S -- siona@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
| If music be the food of love, bring me a doggie bag.
Creating a new type with an extension module [ In reply to ]
Sion Arrowsmith <siona@chiark.greenend.org.uk> wrote:
: In article <faSb3.968$7X1.247240@news.shore.net>,
: Michael P. Reilly <arcege@shore.net> wrote:
:> http://starship.python.net/crew/arcege/extwriting/pyext.html
:>
:>Let me know how well it reads (I doubt it reads well since it was
:>started this morning).

: It's a lot more readable than just source code, and a lot more
: informative with respect to the type and method structures. Any
: chance of you borrowing Guido's time machine so I can read it
: 48 hours ago?

Guido I'm not. ;) Besides, I've had a cold for the last four days -
I'm not sure if it's a good idea for you to get some of my jumbled
thoughts from that far back.

-Arcege