Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Checking for dlls in ctypes
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Wanderer  
View profile  
 More options Oct 12 2012, 11:36 am
Newsgroups: comp.lang.python
From: Wanderer <wande...@dialup4less.com>
Date: Fri, 12 Oct 2012 08:36:27 -0700 (PDT)
Local: Fri, Oct 12 2012 11:36 am
Subject: Checking for dlls in ctypes
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"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Angel  
View profile  
 More options Oct 12 2012, 12:29 pm
Newsgroups: comp.lang.python
From: Dave Angel <d...@davea.name>
Date: Fri, 12 Oct 2012 12:28:17 -0400
Local: Fri, Oct 12 2012 12:28 pm
Subject: Re: Checking for dlls in ctypes
On 10/12/2012 11:36 AM, Wanderer wrote:

I can't help you find the dll's, because I don't run Windows.  But I
could help you write a clearer question:

"doesn't work" is thoroughly useless for describing errors.  If you're
getting an exception, show us the full traceback.  That will show which
statement got the exception that wasn't caught.  Next question is which
of the dlls is missing.  Are you getting an exception because it's
missing or because of something more fundamental, like nesting exception
handlers?

Using bare excepts is almost never a good idea.  If it "works" you get
no clues what went wrong.  For example, a typo in source code can
trigger a bare exception, as can a user typing Ctrl-C.   So when you're
using bare excepts, you have robbed the user of any way to terminate the
program.

If I were you, I'd be writing a loop so there's only one try block.  Too
much duplicated code in the way you're doing it.

--

DaveA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
MRAB  
View profile  
 More options Oct 12 2012, 12:57 pm
Newsgroups: comp.lang.python
From: MRAB <pyt...@mrabarnett.plus.com>
Date: Fri, 12 Oct 2012 17:57:02 +0100
Local: Fri, Oct 12 2012 12:57 pm
Subject: Re: Checking for dlls in ctypes
On 2012-10-12 16:36, Wanderer wrote:

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wanderer  
View profile  
 More options Oct 12 2012, 1:52 pm
Newsgroups: comp.lang.python
From: Wanderer <wande...@dialup4less.com>
Date: Fri, 12 Oct 2012 10:52:38 -0700 (PDT)
Local: Fri, Oct 12 2012 1:52 pm
Subject: Re: Checking for dlls in ctypes

Yes that works for me, too. Thanks

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wanderer  
View profile  
 More options Oct 12 2012, 1:52 pm
Newsgroups: comp.lang.python
From: Wanderer <wande...@dialup4less.com>
Date: Fri, 12 Oct 2012 10:52:38 -0700 (PDT)
Local: Fri, Oct 12 2012 1:52 pm
Subject: Re: Checking for dlls in ctypes

Yes that works for me, too. Thanks

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wanderer  
View profile  
 More options Oct 12 2012, 1:57 pm
Newsgroups: comp.lang.python
From: Wanderer <wande...@dialup4less.com>
Date: Fri, 12 Oct 2012 10:57:09 -0700 (PDT)
Local: Fri, Oct 12 2012 1:57 pm
Subject: Re: Checking for dlls in ctypes

Sorry. It was a WindowsError, but the code I posted now works for me and I can't reproduce the problem. I'll be more diligent in the future.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wanderer  
View profile  
 More options Oct 12 2012, 1:57 pm
Newsgroups: comp.lang.python
From: Wanderer <wande...@dialup4less.com>
Date: Fri, 12 Oct 2012 10:57:09 -0700 (PDT)
Local: Fri, Oct 12 2012 1:57 pm
Subject: Re: Checking for dlls in ctypes

Sorry. It was a WindowsError, but the code I posted now works for me and I can't reproduce the problem. I'll be more diligent in the future.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nobody  
View profile  
 More options Oct 13 2012, 7:32 am
Newsgroups: comp.lang.python
From: Nobody <nob...@nowhere.com>
Date: Sat, 13 Oct 2012 12:32:14 +0100
Local: Sat, Oct 13 2012 7:32 am
Subject: Re: Checking for dlls in ctypes

On Fri, 12 Oct 2012 12:28:17 -0400, Dave Angel wrote:
> Using bare excepts is almost never a good idea.  If it "works" you get no
> clues what went wrong.  For example, a typo in source code can trigger a
> bare exception, as can a user typing Ctrl-C.   So when you're using bare
> excepts, you have robbed the user of any way to terminate the program.

If you want to catch any error, use "except StandardError:". That covers
all errors but not things like KeyboardInterrupt (Ctrl-C) or SystemExit
(sys.exit()).

In situations such as this, where you try multiple candidates until one
succeeds, there's no reason to be any more specific than that. In any
case, Python's lack of formal interfaces makes it hard to reliably be more
specific.

However: you should bear in mind that loading the wrong DLL may just
result in an OS-level exception (e.g. segfault), which can't be caught.
It's preferable to allow the DLL to be explicitly selected e.g. in a
configuration file.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
88888 Dihedral  
View profile  
 More options Oct 13 2012, 9:40 am
Newsgroups: comp.lang.python
From: 88888 Dihedral <dihedral88...@googlemail.com>
Date: Sat, 13 Oct 2012 06:40:01 -0700 (PDT)
Local: Sat, Oct 13 2012 9:40 am
Subject: Re: Checking for dlls in ctypes
Wanderer於 2012年10月12日星期五UTC+8下午11時36分27秒寫道:

In linux  there are shared libraries that could be linked in the runtime.

But for the security concerns this requres the system administrator account
to install shared libraries.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »