Re: No os.copy()? Why not?

2012-04-04 Thread Chris Angelico
On Thu, Apr 5, 2012 at 1:15 AM, Steve Howell wrote: > On Apr 4, 1:37 am, Chris Angelico wrote: >> And, as a subtle point: This method can't create the file "at size". I >> don't know how it'll end up allocating space, but certainly there's no >> opportunity to announce to the OS at file open/crea

Re: No os.copy()? Why not?

2012-04-04 Thread Nobody
On Wed, 04 Apr 2012 08:14:18 -0400, Roy Smith wrote: >> And sparse files are really hard to reproduce, at least on Unix: on >> Linux even the system's cp doesn't guarantee sparseness of the copy (the >> manual mentions a "crude heuristic"). > > I imagine the heuristic is to look for blocks of all

Re: No os.copy()? Why not?

2012-04-04 Thread Steve Howell
On Apr 4, 1:37 am, Chris Angelico wrote: > On Wed, Apr 4, 2012 at 3:53 PM, Steven D'Aprano > > wrote: > > On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > > >> def cp(infile, outfile): > >>    open(outfile, "w").write(open(infile).read()) > > > Because your cp doesn't copy the FILE, it co

Re: No os.copy()? Why not?

2012-04-04 Thread Thomas Rachel
Am 03.04.2012 11:34 schrieb John Ladasky: I use subprocess.call() for quite a few other things. I just figured that I should use the tidier modules whenever I can. Of course. I only wanted to point out that os.system() is an even worse approach. shutils.copy() is by far better, of course. --

Re: No os.copy()? Why not?

2012-04-04 Thread Chris Angelico
On Wed, Apr 4, 2012 at 10:08 PM, Roy Smith wrote: > Slightly off-topic, but are there file systems these days which support > off-line copying?  If I have a disk at the other end of a network link, > it would be nice to tell the disk to copy a file and tell me when it's > done. Depends on your ne

Re: No os.copy()? Why not?

2012-04-04 Thread Roy Smith
In article <87fwcj4zru@dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: > And sparse files are really hard to reproduce, at least on Unix: on > Linux even the system's cp doesn't guarantee sparseness of the copy (the > manual mentions a "crude heuristic"). I imagine the heuristic is to look f

Re: No os.copy()? Why not?

2012-04-04 Thread Roy Smith
On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > > cp is not a system command, it's a shell command. Why not just use the > > incredibly simple and portable > > > >>>>open("outfile", "w").write(open("infile").read()) In article <4f7be1e8$0$2$c3e8da3$54964...@news.astraweb.com>,

Re: No os.copy()? Why not?

2012-04-04 Thread Alain Ketterlin
Steven D'Aprano writes: > On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > >> On 03/28/12 16:12, John Ladasky wrote: >>> I'm looking for a Python (2.7) equivalent to the Unix "cp" command. >>>>>open("outfile", "w").write(open("infile").read()) > Because your cp doesn't copy the FIL

Re: No os.copy()? Why not?

2012-04-04 Thread Chris Angelico
On Wed, Apr 4, 2012 at 3:53 PM, Steven D'Aprano wrote: > On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > >> def cp(infile, outfile): >>    open(outfile, "w").write(open(infile).read()) > > Because your cp doesn't copy the FILE, it copies the file's CONTENTS, > which are not the same thing

Re: No os.copy()? Why not?

2012-04-03 Thread Steven D'Aprano
On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > On 03/28/12 16:12, John Ladasky wrote: >> I'm looking for a Python (2.7) equivalent to the Unix "cp" command. >> Since the equivalents of "rm" and "mkdir" are in the os module, I >> figured I look there. I haven't found anything in the docu

Re: Re: No os.copy()? Why not?

2012-04-03 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Tycho Andersen wrote: Note, though, that this reads the whole file into memory. As many others have said, shutil is the most idiomatic option. * most idiomatic * clearest in terms of showing intent * potentially fastest * hardest to screw up (unlike concatenating file

Re: No os.copy()? Why not?

2012-04-03 Thread Tycho Andersen
On Tue, Apr 03, 2012 at 03:46:31PM -0400, D'Arcy Cain wrote: > On 03/28/12 16:12, John Ladasky wrote: > >I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > >Since the equivalents of "rm" and "mkdir" are in the os module, I > >figured I look there. I haven't found anything in the

Re: No os.copy()? Why not?

2012-04-03 Thread D'Arcy Cain
On 03/28/12 16:12, John Ladasky wrote: I'm looking for a Python (2.7) equivalent to the Unix "cp" command. Since the equivalents of "rm" and "mkdir" are in the os module, I figured I look there. I haven't found anything in the documentation. I am also looking through the Python source code in os

Re: No os.copy()? Why not?

2012-04-03 Thread Ian Kelly
On Tue, Apr 3, 2012 at 12:24 AM, Thomas Rachel wrote: > Am 02.04.2012 23:11 schrieb HoneyMonster: > > >> One way: >> import os >> >> os.system ("cp src sink") > > > Yes. The worst way you could imagine. > > Why not the much much better > > from subprocess > subprocess.call(['cp', 'src', 'sink'])

Re: No os.copy()? Why not?

2012-04-03 Thread John Ladasky
I use subprocess.call() for quite a few other things. I just figured that I should use the tidier modules whenever I can. -- http://mail.python.org/mailman/listinfo/python-list

Re: No os.copy()? Why not?

2012-04-02 Thread Thomas Rachel
Am 02.04.2012 23:11 schrieb HoneyMonster: One way: import os os.system ("cp src sink") Yes. The worst way you could imagine. Why not the much much better from subprocess subprocess.call(['cp', 'src', 'sink']) ? Then you can call it with (really) arbitrary file names: def call_cp(from, t

Re: No os.copy()? Why not?

2012-04-02 Thread HoneyMonster
On Wed, 28 Mar 2012 13:12:30 -0700, John Ladasky wrote: > I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > Since the equivalents of "rm" and "mkdir" are in the os module, I > figured I look there. I haven't found anything in the documentation. > I am also looking through the

Re: No os.copy()? Why not?

2012-04-02 Thread Ian Kelly
On Wed, Mar 28, 2012 at 2:12 PM, John Ladasky wrote: > I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > Since the equivalents of "rm" and "mkdir" are in the os module, I > figured I look there.  I haven't found anything in the documentation. > I am also looking through the Pyt

Re: No os.copy()? Why not?

2012-04-02 Thread John Ladasky
On Mar 28, 9:50 pm, alex23 wrote: > On Mar 29, 6:12 am, John Ladasky wrote: > > > I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > > Any help?  Thanks. > > Try the shutil module:http://docs.python.org/library/shutil.html Many thanks! That's what I was looking for. -- http:

No os.copy()? Why not?

2012-04-02 Thread John Ladasky
I'm looking for a Python (2.7) equivalent to the Unix "cp" command. Since the equivalents of "rm" and "mkdir" are in the os module, I figured I look there. I haven't found anything in the documentation. I am also looking through the Python source code in os.py and its child, posixfile.py. Any hel