[Tutor] Adding ctypes to an application with python 2.2

Alan Gauld alan.gauld at btinternet.com
Mon Jun 9 01:02:41 CEST 2008


"S. Doron" <hedetet at gmail.com> wrote

> Hello, I'm new to this list. What I'd like to do is add support for 
> pointers
> to an old version of python (2.2) in an existing application (a 
> game).

What do you mean by "add support for pointers"?
Pointers are a very low level memory specific thing in C.
In Pascal they are a much higher level logical concept.
In Python every variable is a reference to a value, a pointer if you 
like.

So what kind of pointer do you want and why?
What do you intend to do with these pointers?

>  I found the ctypes module which is supposed to add
> this capability to python.

Not exactly. As the name suggests ctypes allows Python
to access code written in C. On Windows that usually means
code stored in a DLL. It does not add any new pointer
capability to Python itself.

> Alternatively, if it's possible (or easier) to just replace the 
> preexisting
> version of python with 2.5 by messing around with the dll's somehow,
> instructions on how to do so would be welcome.

Again, I don't know what replacing 2.2 with 2.5 would give you
that you need?

> highschool programming, and online python tutorials), but have 
> little
> experience in interfacing with windows, dlls, files, etc. In case 
> you're
> wondering what I need the pointers for, it's for accessing 
> lower-level
> functions from the game's console/script files, that aren't 
> otherwise
> available (I've used dir() to get a list of object methods).

OK, that probably does need ctypes which wuill let you access the
functions and convert from the C types to the more usual Python types.
There are some ctypes tutorials and examples around which should help.

Alan G.




More information about the Tutor mailing list