Blog Archive for December 9, 2009

Basic Python ctypes

December 9, 2009

The easiest way to call C from Python seems to be ctypes.

Simple Example on Windows

>>> import ctypes
>>> libc = ctypes.CDLL("msvcrt")
>>> print libc.strlen("Hello!")
6
>>> libc.printf("Argument");
Argument8
>>> num_bytes = libc.printf("the number %d and string %s\n", 10, "spam")
the number 10 and string spam
>>> print num_bytes …

Python exec statement

December 9, 2009

The exec statement in Python can be used to run code sourced from somewhere at runtime. However, it's important that the line endings are \n, not \r\n.

I was loading code from a database at runtime, and I had a problem where running the script resulted in a Syntax Error. …

Tags: python exec

SQL Link Errors with Oracle

December 9, 2009

We have a strange situation where we have Oracle 10, linked to Oracle 8, linked to Oracle 7. This is so we can keep an existing front end that only supports the Oracle 7 database, whilst developing a new one that only supports Oracle 10. What fun.

We got this …

Tags: oracle link