file copy portability

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Smith

    #1

    file copy portability

    Is shutil.copyfile (src,dst) the *most* portable way to copy files with
    Python? I'm dealing with plain text files on Windows, Linux and Mac OSX.

    Thanks!
  • Peter Hansen

    #2
    Re: file copy portability

    Bob Smith wrote:[color=blue]
    > Is shutil.copyfile (src,dst) the *most* portable way to copy files with
    > Python? I'm dealing with plain text files on Windows, Linux and Mac OSX.[/color]

    Yes, provided you don't need any of the features provided by the
    other shutil.copy functions, and assuming you can live with the
    Caveat listed in the docs for the MacOS system...

    -Peter

    Comment

    • Steve Holden

      #3
      Re: file copy portability

      Bob Smith wrote:
      [color=blue]
      > Is shutil.copyfile (src,dst) the *most* portable way to copy files with
      > Python? I'm dealing with plain text files on Windows, Linux and Mac OSX.
      >
      > Thanks![/color]

      Yes.

      regards
      Steve
      --
      Steve Holden http://www.holdenweb.com/
      Python Web Programming http://pydish.holdenweb.com/
      Holden Web LLC +1 703 861 4237 +1 800 494 3119

      Comment

      • John Machin

        #4
        Re: file copy portability


        Bob Smith wrote:[color=blue]
        > Is shutil.copyfile (src,dst) the *most* portable way to copy files[/color]
        with[color=blue]
        > Python? I'm dealing with plain text files on Windows, Linux and Mac[/color]
        OSX.[color=blue]
        >
        > Thanks![/color]

        Portable what? Way of copying??

        Do you want your files transferred (a) so that they look like native
        text files on the destination system, or (b) so that they are exact
        byte-wise copies?

        A 5-second squint at the source (Lib/shutil.py) indicates that it
        provides, reliably and portably, option b:
        fsrc = open(src, 'rb')
        fdst = open(dst, 'wb')

        One way of doing option (a): you would need to be running Python on the
        destination system, open the src file with 'rU', open the dst file with
        'w'.

        Comment

        • Bob Smith

          #5
          Re: file copy portability

          John Machin wrote:[color=blue]
          > Bob Smith wrote:
          >[color=green]
          >>Is shutil.copyfile (src,dst) the *most* portable way to copy files[/color]
          >
          > with
          >[color=green]
          >>Python? I'm dealing with plain text files on Windows, Linux and Mac[/color]
          >
          > OSX.
          >[color=green]
          >>Thanks![/color]
          >
          >
          > Portable what? Way of copying??
          >
          > Do you want your files transferred (a) so that they look like native
          > text files on the destination system, or (b) so that they are exact
          > byte-wise copies?
          >
          > A 5-second squint at the source (Lib/shutil.py) indicates that it
          > provides, reliably and portably, option b:
          > fsrc = open(src, 'rb')
          > fdst = open(dst, 'wb')
          >
          > One way of doing option (a): you would need to be running Python on the
          > destination system, open the src file with 'rU', open the dst file with
          > 'w'.
          >[/color]

          The files are not copied from one platform to the other. The app must
          run on all platforms. I want to make the app as portable as possible to
          reduce platform specific code.

          Comment

          Working...