473,549 Members | 4,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UNC paths in file object open

I ma trying to open a file on a network share

ie \\servername\sh are\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.or g.uk

Jul 18 '05 #1
4 14471
Graham,

path=r"\\server name\sharr\fold er\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="\\\\serve rname\\share\\f older\\file.ext "

-Larry Bates
"Graham" <gs****@oxfam.o rg.uk> wrote in message
news:40******** **************@ reading.news.pi pex.net...
I ma trying to open a file on a network share

ie \\servername\sh are\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.or g.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.o rg.uk> schrieb im Newsbeitrag
news:40******** **************@ reading.news.pi pex.net...
I ma trying to open a file on a network share

ie \\servername\sh are\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.or g.uk

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

ie \\servername\sh are\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\sha re'
r'\\server\shar e'

C:\Documents and Settings\cary>p ython
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.o rg.uk> wrote in message
news:40******** **************@ reading.news.pi pex.net... I ma trying to open a file on a network share

ie \\servername\sh are\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.or g.uk

Jul 18 '05 #5

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

Similar topics

5
10128
by: simon place | last post by:
is the code below meant to produce rubbish?, i had expected an exception. f=file('readme.txt','w') f.write(' ') f.read() ( PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) on win32. ) I got this while experimenting, trying to figure out the file objects modes,
1
1498
by: Matthew Wilson | last post by:
I have a bunch of classes that track data for time series. The classes are really just glorified dicts where the key is a date object, and the value is the value as of that date. I want a way to store a bunch of these tseries objects into a file object. I want to be able to open the file object, iterate through all timeseries, then create...
0
1324
by: Dan Perl | last post by:
Here is some code to illustrate a problem that I have: import copy class myc: def __init__(self): self.myf=file('bar.txt',"w") def foo(self): self.myf.write('hello world!') # it's going to fail for d.foo( ) c = myc()
5
2111
by: John Marshall | last post by:
Hi, Does anyone see a problem with doing: data = file("tata").read() Each time this is done, I see a new file descriptor allocated (Linux) but not released. 1) Will there ever be a point where I
1
3018
by: Matthew Thorley | last post by:
I've been using tarfile like this import tarfile tar = tarfile.open('path_to_tar_archive', 'r:gz') But I need to use it like this: archive = open('path_to_tar_archive', 'r') tar = tarfile.open(archive.readlines())
0
1887
by: travis ray | last post by:
Hi, I have an extension in which a file object is created in python and passed down to a c extension which attempts to read from it or write to it. Writing to the file pointer seems to work okay, but reading from it results in EBADF. It also causes python to crash on exit. I've attached the minimal (I think) c code, python code, build...
0
2545
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a datalist. When the next user selects trys to run the page, the page fails and I get a generic error message from the stack trace. I am assuming...
28
1797
by: John Salerno | last post by:
What is the best way of altering something (in my case, a file) while you are iterating over it? I've tried this before by accident and got an error, naturally. I'm trying to read the lines of a file and remove all the blank ones. One solution I tried is to open the file and use readlines(), then copy that list into another variable, but...
7
2160
by: Michael Castleton | last post by:
When I open a csv or txt file with: infile = open(sys.argv,'rb').readlines() or infile = open(sys.argv,'rb').read() and then look at the first few lines of the file there is a carriage return + line feed at the end of each line - \r\n This is fine and somewhat expected. My problem comes from then writing
0
7526
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7455
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5373
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.