snippets : cross platform library loader helper

Python : cross platform library loader helperdrax's answer for loading a named or absolute library on any platform :)
import os, sys, ctypes

# Types reminder:
#!/usr/bin/python
# String  : ctypes.c_char_p
# Integer : ctypes.c_int
# Long    : c_ulonglong

def loadbinlib(libname="", libpath=""):
   if not libpath:
       if sys.platform in ['win32','win64']:
          libpath = '%s.dll' % libname
       elif sys.platform in ['mac']:
          libpath = '%s.dylib' % libname
       elif sys.platform in ['linux', 'linux2']:
          libpath = '%s.so' % libname
   return ctypes.CDLL(libpath)
tags : python, system, linux, windows

all tags : python, system, vlc, video, apache, proxy, linux, django, MySQL, .NET, XML, XSL, regexp, bat, windows, bash, git

back to snippets home
site réalisé et hébergé par revolunet © 2009 - informations légales