maybe following recipe from activestate may be usefull. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496960 http://sebulba.wikispaces.com/recipe+thread2