Saved for later reference

online repository of stuff I had to google for hours to figure out – and random snippets of code

Mercurial module for Python 2.6/Win32

Tags: , , , , , , ,

I’ve compiled Mercurial 1.5.4 for Python 2.6, following this guide, and uploaded it here, since I guess it’ll be useful for later:

mercurial-1.5.4.win32-py2.6.exe

I use it for Trac 0.12 in a multi-repository setting, so we can keep our old SVN repo while having some of the larger projects on Hg.

Share

lxml for Python 2.6/win32

Tags: , , , ,

A quick post today: Using these instructions, I’ve built a statically linked lxml 2.2.4 for Windows.

I used the following versions of the libraries:

1
2
3
4
5
6
STATIC_INCLUDE_DIRS = [
"..\\libxml2-2.7.6.win32\\include",
"..\\libxslt-1.1.26.win32\\include",
"..\\zlib-1.2.3.win32\\include",
"..\\iconv-1.9.2.win32\\include"
]
1
2
3
4
5
6
STATIC_LIBRARY_DIRS = [
"..\\libxml2-2.7.6.win32\\lib",
"..\\libxslt-1.1.26.win32\\lib",
"..\\zlib-1.2.3.win32\\lib",
"..\\iconv-1.9.2.win32\\lib"
]

Download it here: lxml-2.2.4.win32-py2.6

Share

Simple Python ctypes Example – in Windows

Tags: , , , , , ,

I found this blog post, Simple Python ctypes Example, on Reddit, and thought I’d see how different the procedure was for Windows.

What you’ll need:

Creating the DLL

Create a file dlltest.c with the following content:

1
2
3
4
5
6
7
8
9
10
11
12
#include <windows.h>

BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}

__declspec(dllexport) int
multiply(int num1, int num2)
{
return num1 * num2;
}

Start the Visual Studio 2008 Command Prompt from the Start Menu (this sets up the path for the compiler and other files, which makes things easier) and go to the directory you saved dlltest.c to.

Compile it with the following command:

cl -LD dlltest.c -Fetest.dll

Testing the DLL

As in the original Linux example, this DLL is easily tested using similar commands:

1
2
3
4
>>> from ctypes import *
>>> libtest = cdll.LoadLibrary('test.dll')
>>> print libtest.multiply(2, 2)
4

So, that is the simplest DLL possible, I’ll look at (same as the original blog post) applying it to more complex examples later.

Share

© 2009 Saved for later reference. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.