Checking for dlls in ctypes

Wanderer wanderer at dialup4less.com
Fri Oct 12 13:52:38 EDT 2012


On Friday, October 12, 2012 12:57:06 PM UTC-4, MRAB wrote:
> On 2012-10-12 16:36, Wanderer wrote:
> 
> > I'm trying to write some code that will load one of three dll depending on the one available. I've tried the code below, but it doesn't work. The try except doesn't catch the exception. Is there a way to do this?
> 
> >
> 
> >          try:
> 
> >              self.dll = windll.pvcam64
> 
> >          except:
> 
> >              print "No pvcam64"
> 
> >              try:
> 
> >                  self.dll = windll.pvcam32
> 
> >              except:
> 
> >                  print "No pvcam32"
> 
> >                  try:
> 
> >                      self.dll = windll.pvcam
> 
> >                  except:
> 
> >                      print "No pvcam"
> 
> >                      return
> 
> >                  else:
> 
> >                      print "installed pvcam"
> 
> >              else:
> 
> >                  print "installed pvcam32"
> 
> >          else:
> 
> >              print "installed pvcam64"
> 
> >
> 
> This works for me:
> 
> 
> 
>      for name in ("pvcam64", "pvcam32", "pvcam"):
> 
>          try:
> 
>              self.dll = getattr(windll, name)
> 
>          except OSError:
> 
>              print "No " + name
> 
>          else:
> 
>              print "Installed " + name
> 
>              return

Yes that works for me, too. Thanks



More information about the Python-list mailing list