Unsung Modules Redux
Dave Brueck
dave at pythonapocrypha.com
Fri Dec 20 11:48:57 EST 2002
On Fri, 20 Dec 2002, Scherer, Bill wrote:
> So, what's your favorite unsung module today?
ctypes!
With stuff like Pysco and Pyrex maturing, the main reason I was still
writing C extensions was to access various Windows APIs (especially those
not covered in the Win32 Python extensions), but no longer - I may never
write another "wrapper" extension again and that makes me very, very
happy. :)
For example, here's some code that normally would live in a C extension:
from ctypes import windll, c_string
def GetDesktopPath():
'Returns the path to the desktop folder or an empty string on error'
path = c_string('\000' * 1000)
if windll.shfolder.SHGetFolderPathA(0, 0x0010, 0, 0, path) == 0:
return path.value
return ''
Woohoo!
-Dave
More information about the Python-list
mailing list