How to open a remote file using python.
odeits at gmail.com
Mon Feb 23 00:06:10 EST 2009
On Feb 22, 9:02 pm, "venutaurus... at gmail.com"
<venutaurus... at gmail.com> wrote:
> On Feb 23, 9:25 am, MRAB <goo... at mrabarnett.plus.com> wrote:
> > venutaurus... at gmail.com wrote:
> > > Hello all,
> > > I am writing an application where I need to open a shared
> > > file on a remote machine using python script. I tried using the
> > > following function:
> > > f = urllib.open("\\remote_machine\\folder1\\file1.doc")
> > > I also tried using
> > > class urllib.FancyURLopener(...)
> > > but didn't work. Can some one help me in this regard.
> > What do you mean by "remote machine"? Do you mean you want to open a
> > file that's in a shared folder on a machine that's on the same local
> > network?
> > If it's meant to be a Windows filepath then it should be:
> > f = open(r"\\remote_machine\folder1\file1.doc")
> > (If the file is a Microsoft Word document file, then you won't probably
> > be able to make much sense of its contents using open().)
> Thanks to all for your brisk replies:
> Yes, my aim is to open a file from another machine in the same
> LAN. It also worked using
> >>f = urllib.urlopen("\\\remote_machine\\folder\\file.doc")
> But now I also have to copy the same file to the local machine
> in Python. Do I need to follow any protocols for this?
> Thank you,
the copy in shutil will work just fine.
More information about the Python-list