strange transliteration in win32com.client

M

Mark Morss

Is this the place to ask a win32com.client question? I am a unix
person trying to run on windows, so I have little familiarity with
this module. I have this code:

import win32com.client

"""An Access connection"""

def connect(data_source, user, pwd, mdw):
connAccess = win32com.client.Dispatch(r'ADODB.Connection')
SOURCE=%s;USER ID=%s;PASSWORD=%s;Jet OLEDB:System Database=%s;"
% (data_source, user, pwd, mdw)
connAccess.Open(DSN)
return connAccess

I when I call this, running my program from the windows command line
on the C:\ drive, with data_source='\\Hqwhslfs001\office\risk oversight
\myaccessdb.mdb', which is the fully specified drive name, it comes
back with:

File "C:\Python25\lib\site-packages\win32com\client\dynamic.py",
line 258, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags,
retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
'Microsoft JET Database Engine', "'c:\\Hqwhslfs001\\office\risk
oversight\\myaccess.mdb' is not a valid path. Make sure that the path
name is spelled correctly and that you are connected to the server on
which the file resides.", None, 5003044, -2147467259), None)

Please note the strange insertion of double slashes in the indicated
'not valid path.' Also the insertion of 'c:' and the strange leading
double quotation mark.

When I call it with data_source = 'V:\risk oversight\myassessdb.mdb',
which reflects how this same drive is mapped on my machine, I get:

File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line
258, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags,
retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
'Microsoft JET Database Engine', "'v:\\\risk oversight\
\myaccessdb.mdb' is not a valid path. Make sure that the path name is
spelled correctly and that you are connected to the server on which
the file resides.", None, 5003044, -2147467259), None)

Note the weird transliteration of data_source. I am powerless to
understand this.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

'Microsoft JET Database Engine', "'c:\\Hqwhslfs001\\office\risk
oversight\\myaccess.mdb' is not a valid path. Make sure that the path
name is spelled correctly and that you are connected to the server on
which the file resides.", None, 5003044, -2147467259), None)

Please note the strange insertion of double slashes in the indicated
'not valid path.'

That is not strange at all. In Python, the \ character in a string
literal is an escape character, see

http://docs.python.org/ref/strings.html

When Python prints out a string in its "repr", it always uses the
source code notation to print it back.

So if you want to have a single backslash in a string, you have to put
two backslashes into the source code.
When I call it with data_source = 'V:\risk oversight\myassessdb.mdb',
which reflects how this same drive is mapped on my machine, I get:

'Microsoft JET Database Engine', "'v:\\\risk oversight\
\myaccessdb.mdb' is not a valid path.

Note the weird transliteration of data_source. I am powerless to
understand this.

In your source code, \r is not a backslash-followed-by-r, but a
carriage-return character (so it's a single character, not two);
also in the first example. Windows finds that the file you denote
here does not exist - you don't have any files with a carriage
return in their file name on your disk.

In addition, Windows considers V:foo as a relative path; relative
to the current directory on drive V. So V:foo is a short-hand
for V:\foo, which, as a Python string, reads 'V:\\foo'. As you
have the director '\risk oversight' specified (which starts
with CR), the full normalized string will display with three
consecutive \ characters.

You can avoid quoting all backslashes by using raw strings
(see above URL).

HTH,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top