A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2005-December/059099.html below:

[Python-Dev] file() vs open(), round 7

[Python-Dev] file() vs open(), round 7Fredrik Lundh fredrik at pythonware.com
Tue Dec 27 14:35:29 CET 2005
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)

</F> 



More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4