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.
Fair enough. > Here's a rough draft: > > def textopen(name, mode="r", encoding=None): > if "U" not in mode: > mode += "U" The "U" is not needed when opening files using codecs - these always break lines using .splitlines() which breaks lines according to the Unicode rules and also knows about the various line break variants on different platforms. > if encoding: > return codecs.open(name, mode, encoding) > return file(name, mode) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Dec 27 2005) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: _______________________________________________ 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