Oddity is shutil.copyfileobj

Tim Golden tim.golden at viacom-outdoor.co.uk
Thu Jan 20 05:02:25 EST 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.

<code>
import shutil

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

</code>

| 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:

<code>
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:
            break
        fdst.write(buf)
</code>

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.

TJG

________________________________________________________________________
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:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list