At 02:35 PM 12/27/2005 +0100, Fredrik Lundh wrote: >M.-A. Lemburg wrote: > > >> can we add a opentext factory for file/codecs.open while we're at it ? > > > > Why a new factory function ? Can't we just redirect to codecs.open() > > in case an encoding keyword argument is passed to open() ?! > >I think open is overloaded enough as it is. Using separate functions for >distinct >use cases is also a lot better than keyword trickery. > >Here's a rough draft: > > def textopen(name, mode="r", encoding=None): > if "U" not in mode: > mode += "U" > if encoding: > return codecs.open(name, mode, encoding) > return file(name, mode)
Nice. It should probably also check whether there's a 'b' or 't' in 'mode' and raise an error if so. I'd also prefer to call it 'textfile', as that reads more nicely with "for line in textfile(...):" use cases, and it does return a file object. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com