RE: Oddity is shutil.copyfileobj

Discussion in 'Python' started by Tim Golden, Jan 20, 2005.

  1. Tim Golden

    Tim Golden Guest

    [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
    ________________________________________________________________________
    Tim Golden, Jan 20, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bmgz
    Replies:
    1
    Views:
    1,089
    Hans Nowak
    Dec 16, 2003
  2. Joe

    file copy shutil

    Joe, Feb 9, 2004, in forum: Python
    Replies:
    1
    Views:
    315
    Michael Hudson
    Feb 9, 2004
  3. Stéphane Ninin

    shutil.move, permission denied, why ?

    Stéphane Ninin, Apr 6, 2004, in forum: Python
    Replies:
    8
    Views:
    1,295
    Stéphane Ninin
    Apr 8, 2004
  4. Neil Benn

    Oddity is shutil.copyfileobj

    Neil Benn, Jan 20, 2005, in forum: Python
    Replies:
    0
    Views:
    472
    Neil Benn
    Jan 20, 2005
  5. Fletcher Johnson

    Why is the shutil module called shutil?

    Fletcher Johnson, Sep 24, 2011, in forum: Python
    Replies:
    11
    Views:
    839
    alex23
    Sep 26, 2011
Loading...

Share This Page