strange transliteration in win32com.client

"Martin v. Löwis" martin at v.loewis.de
Tue Oct 23 17:50:29 EDT 2007


> '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



More information about the Python-list mailing list