473,287 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

strange transliteration in win32com.client

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.

Oct 23 '07 #1
1 2713
'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
Oct 23 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Stockton | last post by:
I recently upgraded from ActivePython 2.2.2 to ActivePython 2.3.2 and I'm running into an issue importing the win32com.client module. Before installing the new version, I made sure to properly...
1
by: a_bogdan_marinescu | last post by:
Hello all, I'm trying to do some COM automation from Python (using Mark Hammond's Win32 extensions, of course) and I'm getting some very strange errors. Specifically, I try to use a COM object...
0
by: Paul McGuire | last post by:
Software versions: Python - 2.3.3 win32all extensions - build 163 OS- Win2000 SP4 I am having trouble in accessing a customer's proprietary COM type library. After running makepy against the...
2
by: Sibylle Koczian | last post by:
Hello, I've installed Python 2.4 and the win32 extensions, using administrator rights, under Windows XP in "C:\Programme". As this is a directory without spaces I didn't expect any problems. But...
3
by: tyler.schlosser | last post by:
Hi there, I am trying to launch a program called AmiBroker using the command: AB = win32com.client.Dispatch("Broker.Application") However, I have a dual-core CPU and would like to launch two...
2
by: Ray | last post by:
Hi, I need to use cell's background color. when I record a macro from excel, it shows: Rows("7:7").Select With Selection.Interior .ColorIndex = 8 .Pattern = xlSolid
11
by: Bill Davy | last post by:
I am trying to edit Contacts in Outlook. This is so I can transfer numbers from my address book which is an Excel spreadsheet to my mobile phone. I came across the following snippet of code which...
4
by: sterling | last post by:
I'm curious as to why the difference between IDLE and pythonWin when using win32com. opening an excel file, i've attempted to grab the chart information out of the file. commands like co =...
1
by: Rafe | last post by:
Hi, I'm getting this error: # File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 491, in __getattr__ # raise pythoncom.com_error, details # COM Error: Unspecified...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.