Accessing a file in a network drive (python under win32)

Peter Abel p-abel at t-online.de
Thu Jan 23 18:39:49 EST 2003


akineko at pacbell.net (Aki Niimura) wrote in message news:<b714b8de.0301220949.214886e at posting.google.com>...
> Hi everyone,
> 
> I'm porting a program written in Unix to Windows environment.
> 
> When I tried to open a file in a network drive (which is from SAMBA server) 
> using tkFileDialog.askopenfile(), I got the following error message:
> IOError: [Errno 2] No such file or directory: '//Evelyn/ms_share/python_win32/jt
> ag/t.py'
> 
It depends on your current workdevice
'//Evelyn/ms_share/python_win32/jtag/t.py'
is looking for the above directory on your current device
> However ...
> (1) It won't complain if I access a file in a local drive (ex) 'C:/config.sys'

Here you're searching config.sys explicitly on device C:
e.g saying os.chdir('d:')
will show 
>>> os.getcwd()
'D:\\'
But now
>>> os.chdir('\\windows')
will fail
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
OSError: [Errno 2] No such file or directory: '\\windows'
because windows is on C:
So 
>>> os.chdir('c:\\windows')
helps and shows
>>> os.getcwd()
'c:\\windows'

> (2) I can open the file from IDLE Python Shell
> >>> fd = open('//Evelyn/ms_share/python_win32/jtag/t.py', 'r')
> 
> Does anybody have an idea what is going on here?
> I'm not export on Windows. But why can't Windows be more like Unix?

I think before your open( ... ) command you changed your device.

> 
> Any info would be highly appreciated.
> 
> Aki-

BTW
In Python 
  open( 'C:\\windows\\system32') is equivalent to
  open(r'C:\windows\system32') is equivalent to
  open( 'C:/windows/system32') 
The '\' is an escape-character to indicate
special characters as Tab: '\t', newline: '\n' etc. or
!!!!! Backslash: '\\' !!!!!
To avoid '\\' you can use so-called raw-strings which
start with an r' ... ' and you can write 
Backslash: r'\'

Hope, I could help you
Peter




More information about the Python-list mailing list