Oddity is shutil.copyfileobj

Tim Golden tim.golden at viacom-outdoor.co.uk
Thu Jan 20 11:02:25 CET 2005

[Neil Benn]
| I'm running a program which is using 
| shutil.copyfileobj on a Win2K Pro, python 2.3 box.  

Just for (possible) reassurance, I've just
run the following code snippet on my Win2k
Python 2.3.4 box and it seemed to work
without adding any oddities to the file name. 
I'm copying to a "real" Windows file share, not
a Samba box, so it may make a difference.

import shutil

f = open ("test.py", "rt")
g = open (r"\\tdi_nt4a\user\goldent\temp\test.py", "wt")
  shutil.copyfileobj (f, g)
  f.close ()
  g.close ()


| The source and dest file are both opened in 
| textual mode as 'w'

Well my first question (which may or may not be relevant)
is: what do you mean by this? Are they both opened for
*writing*, which is what the "w" implies? Or was that
merely a typo for "t", meaning that you had explcitly
selected text mode as opposed to binary mode?

| The files are copied across perfectly (diffing them shows
| they are identical), however I have one small problem, 
| the destination filename has .read appended to the end.  
| I've checked my code again and again and I'm definatly 
| not apeending this.

Any chance you could *post* the code (at least the
section in question)? The source for copyfileobj, which
was the first place I looked is this:

def copyfileobj(fsrc, fdst, length=16*1024):
    """copy data from file-like object fsrc to file-like object fdst"""
    while 1:
        buf = fsrc.read(length)
        if not buf:

And unless there's something *really* subtle going on,
I'm not sure I could spot any filename changing there.
I'm afraid that, short of some obscure bug in Samba,
which should show up regardless of what you're copying
across, your own code is the most likely culprit.


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

More information about the Python-list mailing list