[Tutor] ctypes question

Albert-Jan Roskam fomcl at yahoo.com
Tue Mar 8 10:00:33 CET 2011

Hi all,

Thanks for your replies. It wasn't a permissions issue. Apparently, not the full 
path name should be used. When I use os.chdir (by the way: why on earth isn't 
this called os.setcwd()?? That's consistent with os.getcwd()) and then use the 
file name only, it works. See the Idle session below. Thought it'd be nice to 
share this with you.

Best wishes,

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on 
IDLE 1.2.4      
>>> import ctypes
>>> lib = ctypes.cdll.LoadLibrary("d:/temp/spss_io/win32/spssio32.dll")

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    lib = ctypes.cdll.LoadLibrary("d:/temp/spss_io/win32/spssio32.dll")
  File "C:\Python25\lib\ctypes\__init__.py", line 431, in LoadLibrary
    return self._dlltype(name)
  File "C:\Python25\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] Kan opgegeven module niet vinden
>>> import os
>>> os.path.exists("d:/temp/spss_io/win32/spssio32.dll")
>>> os.chdir("d:/temp/spss_io/win32")
>>> lib = ctypes.cdll.LoadLibrary("spssio32.dll")
>>> dir(lib)
['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__', '__getattr__', 
'__getattribute__', '__getitem__', '__hash__', '__init__', '__module__', 
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 
'__weakref__', '_handle', '_name']


All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have the 
Romans ever done for us?

From: Alan Gauld <alan.gauld at btinternet.com>
To: tutor at python.org
Sent: Mon, March 7, 2011 7:26:15 PM
Subject: Re: [Tutor] ctypes question

"Pacific Morrowind" <pacificmorrowind at gmail.com> wrote

> but that path doesn't actually exist... replace that path with either
> r"d:/temp/spssio32.dll" or with "d://temp//spssio32.dll"; otherwise the
> /t will be transformed into a tab.

You've got your / and \ mixed up.

Forward slashes (/) are fine in Windows paths. It's back
slashes(\) that need escaping or raw stringing. \t is tab...

On the original ask - could it be a permissions issue?
Does your app have acess to the file?

Alan G. 

Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110308/c7f18555/attachment.html>

More information about the Tutor mailing list