469,890 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

UNC paths in file object open

I ma trying to open a file on a network share

ie \\servername\share\folder\file

afile = open( \\server\share\folder\file, "r" )

have also tried
afile = open( //server/share/folder/file, "r" ) # as per the Python cookbook
advice on page 113 namely " use / regardless of the proclivities of the
underlying operating system".

Neither work.

I am running python on XP and accessing win 2000 share.

Thanks for any help

Graham Smith

PeopleSoft Technical Team Leader
OXFAM GB
+44 (1865) 313255
gs****@oxfam.org.uk

Jul 18 '05 #1
4 12951
Graham,

path=r"\\servername\sharr\folder\file.ext"

works on my machine (I use it all the time).

Remember that backslash is an "escape" character so
you must us r"<path>" or double the number of backslashes
without the "r":

path="\\\\servername\\share\\folder\\file.ext"

-Larry Bates
"Graham" <gs****@oxfam.org.uk> wrote in message
news:40**********************@reading.news.pipex.n et...
I ma trying to open a file on a network share

ie \\servername\share\folder\file

afile = open( \\server\share\folder\file, "r" )

have also tried
afile = open( //server/share/folder/file, "r" ) # as per the Python cookbook advice on page 113 namely " use / regardless of the proclivities of the
underlying operating system".

Neither work.

I am running python on XP and accessing win 2000 share.

Thanks for any help

Graham Smith

PeopleSoft Technical Team Leader
OXFAM GB
+44 (1865) 313255
gs****@oxfam.org.uk

Jul 18 '05 #2
What's the error? Can you provide a trceback?

Regards
Franz

P.S.: Im not sure but accessing a share on a machine NOT connected to a
network doesn't work since 2k and XP (worked on NT, though).

"Graham" <gs****@oxfam.org.uk> schrieb im Newsbeitrag
news:40**********************@reading.news.pipex.n et...
I ma trying to open a file on a network share

ie \\servername\share\folder\file

afile = open( \\server\share\folder\file, "r" )

have also tried
afile = open( //server/share/folder/file, "r" ) # as per the Python cookbook advice on page 113 namely " use / regardless of the proclivities of the
underlying operating system".

Neither work.

I am running python on XP and accessing win 2000 share.

Thanks for any help

Graham Smith

PeopleSoft Technical Team Leader
OXFAM GB
+44 (1865) 313255
gs****@oxfam.org.uk

Jul 18 '05 #3
Graham wrote:
I ma trying to open a file on a network share

ie \\servername\share\folder\file

afile = open( \\server\share\folder\file, "r" )

have also tried
afile = open( //server/share/folder/file, "r" ) # as per the Python cookbook
advice on page 113 namely " use / regardless of the proclivities of the
underlying operating system".


Are the above actual examples of the code you typed? If so, I suggest
reviewing the tutorial... strings in Python always require surrounding
quotation marks, either ' or ", and yours above have neither.
Jul 18 '05 #4
works like a champ.

using
'//server/share'
'\\\\server\share'
r'\\server\share'

C:\Documents and Settings\cary>python
ActivePython 2.3.2 Build 231 (ActiveState Corp.) based on
Python 2.3.2 (#49, Nov 6 2003, 10:18:20) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
import os
os.listdir('//pollux/hdc1') ['public', 'archive', 'store'] os.listdir('\\\\pollux\\hdc1') ['public', 'archive', 'store'] os.listdir(r'\\pollux\hdc1') ['public', 'archive', 'store']


BTW, thanks. I hadn't thought of using UNCs


"Graham" <gs****@oxfam.org.uk> wrote in message
news:40**********************@reading.news.pipex.n et... I ma trying to open a file on a network share

ie \\servername\share\folder\file

afile = open( \\server\share\folder\file, "r" )

have also tried
afile = open( //server/share/folder/file, "r" ) # as per the Python cookbook advice on page 113 namely " use / regardless of the proclivities of the
underlying operating system".

Neither work.

I am running python on XP and accessing win 2000 share.

Thanks for any help

Graham Smith

PeopleSoft Technical Team Leader
OXFAM GB
+44 (1865) 313255
gs****@oxfam.org.uk

Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by simon place | last post: by
1 post views Thread by Matthew Wilson | last post: by
reply views Thread by Dan Perl | last post: by
5 posts views Thread by John Marshall | last post: by
1 post views Thread by Matthew Thorley | last post: by
28 posts views Thread by John Salerno | last post: by
7 posts views Thread by Michael Castleton | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.