views:

97

answers:

1

I'm wanting to use an extension for Python that I found here, but I'm using Python 3.1 and when I attempt to compile the C extension included in the package (_wincon), it does not compile due to all the syntax errors. Unfortunately, it was written for 2.x versions of Python and as such includes methods such as PyMember_Get and PyMember_Set, which are no longer part of Python. My problem is that I have not gotten around to learning C and as such have not been able to figure out how to modify the code to use syntax that is still valid in Python 3.1. (There were also a couple macros such as staticforward that need fixing, but I'm assuming those just need to be changed to static.) Therefore: how do I go about fixing this?

(Note that I have indeed looked into various other Windows console interfaces for Python such as the win32con extension in PyWin32), but none of them fit my needs as much as this one appears to.)

+6  A: 

I don't believe there is any magic bullet to make the C sources for a Python extension coded for some old-ish version of Python 2, into valid C sources for one coded for Python 3 -- it takes understanding of C and of how the C API has changed, and of what exactly the extension is doing in each part of its code. Believe me, if we had known of some magic bullet way to do it susbtantially without such human knowledge and understanding, we'd have included a "code generator" (like 2to3 for Python sources -- and even that has substantial limitations!) for such C code translation.

In practice, even though Python 3.1 is per se a mature and production-ready language, you should not yet migrate your code (or write a totally new app) in Python 3.1 if you need some Python 2.* extension that you're unable to port -- stick with 2.6 until the extensions you require are available (or you have learned enough C to port them yourself -- or rewrite them in Cython, which DOES smoothly support Python 2.* and 3.*, with, I believe, just a modicum of care on the programmer's part).

Alex Martelli
I had a feeling that was the case. Anyway, thanks for the advice. Also, I was planning on learning C eventually anyway, so I might as well start now, right?
JAB
@Cat, sure, that seems quite reasonable
Alex Martelli