Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > strange transliteration in win32com.client

Reply
Thread Tools

strange transliteration in win32com.client

 
 
Mark Morss
Guest
Posts: n/a
 
      10-23-2007
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.

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Guest
Posts: n/a
 
      10-23-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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
My perl does not support transliteration? fl Perl Misc 1 11-07-2010 03:05 PM
Ambiguous range in transliteration operator at Roland Mösl Perl Misc 0 09-27-2010 08:58 AM
Transliteration problems Axel Etzold Ruby 2 11-09-2008 10:09 AM
How does the complement work with transliteration ? anita Perl Misc 1 10-08-2004 05:17 AM
Question About Strange 'C' Code Syntax ( Well strange to me anyway ) Harvey Twyman C Programming 8 10-25-2003 05:54 AM



Advertisments