[Tutor] Adding ctypes to an application with python 2.2

S. Doron hedetet at gmail.com
Mon Jun 9 19:48:10 CEST 2008


On Mon, Jun 9, 2008 at 2:02 AM, Alan Gauld <alan.gauld at btinternet.com>
wrote:

> "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.
>
>
I've tried reading tutorials, but I can't make heads or tails of the
installation instructions.
For instance, I'm not sure whether the installation instructions included in
ctypes are even relevant. Do I need to set it up if I just want to add the
module to the application, or do I just copy relevant .py files? Am I
supposed to compile anything? The ctypes\__init__.py file tries to import
_ctypes, but there is no _ctypes.py file (there is a _ctypes.c file,
though).
And do I need libffi installed if I'm using windows? If so, where and how do
I install it? (the libffi readme is kind of fuzzy)

Lastly, should the need to compile the _ctypes.c file arise, what free C
compiler would you recommend?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080609/997e1ff2/attachment.htm>


More information about the Tutor mailing list