strange transliteration in win32com.client

Discussion in 'Python' started by Mark Morss, Oct 23, 2007.

  1. Mark Morss

    Mark Morss Guest

    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.
     
    Mark Morss, Oct 23, 2007
    #1
    1. Advertising

  2. > '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
     
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=, Oct 23, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Justin Stockton
    Replies:
    1
    Views:
    461
    Trent Mick
    Nov 12, 2003
  2. Axel Etzold

    Transliteration problems

    Axel Etzold, Nov 8, 2008, in forum: Ruby
    Replies:
    2
    Views:
    91
    Henrik Nyh
    Nov 9, 2008
  3. anita
    Replies:
    1
    Views:
    80
    Sam Holden
    Oct 8, 2004
  4. Roland Mösl
    Replies:
    0
    Views:
    102
    Roland Mösl
    Sep 27, 2010
  5. fl
    Replies:
    1
    Views:
    97
    Scott Bryce
    Nov 7, 2010
Loading...

Share This Page