[Python-Dev] File Object Copy
Moshe Zadka
Moshe Zadka <moshez@math.huji.ac.il>
Wed, 12 Jul 2000 12:08:26 +0300 (IDT)
On Wed, 12 Jul 2000, Fredrik Lundh wrote:
> footnote: it's definitely an accepted pydiom:
Yes, but one I personally do not like
>
> aifc.py:
> if type(f) == type(''):
> f = __builtin__.open(f, 'rb')
>
> binhex.py:
> if type(ofp) == type(''):
> ofname = ofp
> ofp = open(ofname, 'w')
>
> mimify.py:
> if type(infile) == type(''):
> ifile = open(infile)
>
> pstats.py:
> elif type(arg) == type(""):
> f = 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...).
Of course -- that's why I think most code should use file-like objects.
--
Moshe Zadka <moshez@math.huji.ac.il>
There is no GOD but Python, and HTTP is its prophet.
http://advogato.org/person/moshez