Python and Intranet issues

Gerhard Häring gerhard.haering at gmx.de
Mon Aug 19 15:25:57 EDT 2002


* rcw5459@*nospam*njit.edu <rcw5459@*nospam*njit.edu> [2002-08-19 18:29 +0000]:
> [...] The images were loaded fine...but I'm getting errors when tying
> to read the text file.  At first I used
> open('\\blah\blahblah\info.txt', 'r') to try to get the info, but I
> was getting errors (no such file or directory).  I've also tried
> several variations including: open('\\\\blah\\blahblah\\info.txt',
> 'r') and 

Looks like this is a SMB (Windows) share.

> open('file:///\\\\blah\\blahblah\\info.txt', 'r').  
> 
> Then, after some snooping around, I discovered the urlopen() command.
> After attempting this in several different ways I received more "No
> such file or directory" errors.

I'd recommend to use raw strings for entering Windows file names, like
this:

    r"\\somecomputer\someshare\foo\bar\info.txt" 

As you can see, with raw strings you don't have to escape the
backslashes with an additional backslash, which has the additional
benefit that you can just copy filenames you've got in your Explorer or
Windows commandline into your Python script.

For debugging, you could try to issue os.listdir() on the parts of the
directory tree, like:

os.listdir(r"\\somecomputer\someshare")
os.listdir(r"\\somecomputer\someshare\foo")
os.listdir(r"\\somecomputer\someshare\foo\bar")

This way you should be able to find out where a problem with a wrong
path component or insufficient access permissions is located.

> Can anyone tell me the correct syntax (or correct command, if I'm
> using the wrong ones) to use when trying to read a file off the
> network?  

If it's a network share, "open" is the function to use.

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))




More information about the Python-list mailing list