[Python-Dev] File Object Copy

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Wed, 12 Jul 2000 11:04:27 +0200


moshe wrote:
> > >   1. It would be easy to skip the open and close operations in=20
> > >      'shutil.copyfile', if either 'src' or 'dst' are already open=20
> > >      file objects instead of strings. =20
> >=20
> > -0: Too much Perl-like DWIM magic

footnote: it's definitely an accepted pydiom:

aifc.py:
        if type(f) =3D=3D type(''):
            f =3D __builtin__.open(f, 'rb')

binhex.py:
        if type(ofp) =3D=3D type(''):
            ofname =3D ofp
            ofp =3D open(ofname, 'w')

mimify.py:
 if type(infile) =3D=3D type(''):
  ifile =3D open(infile)

pstats.py:
  elif type(arg) =3D=3D type(""):
   f =3D open(arg, 'rb')

etc.

it's a reasonable way to make your code a bit more reusable
(it's rude to expect every chunk of potentially usable data to
have a filename...).

</F>