Message74727
In the C library, fopen() have two arguments: filename and the mode,
and open() has three arguments: filename, mode and flags. In Python,
open() has 7 arguments:
- file
- mode
- buffering
- encoding
- errors
- newline
- closefd
Most programs only use the two first arguments, but buffering is
sometimes set. Eg. open(filename, "r") or open(filename, "wb", 0).
I think that only the file and mode arguments are easy to understand,
the others have to be specified using their name. Eg.
open(filename, "wb", buffering=0) or open(filename, "r",
encoding="GBK").
I wrote a patch to use keyword only arguments, and another to fix some
libraries and the unit tests.
explicit_open.patch needs review. I don't know the best way to create
a dictionary. Py_BuildValue() may be used to write a smaller patch.
--
open(file, mode, *, buffering, ...) may be replaced by open(file,
mode, buffering, *, ...) to keep compatibility with Python2, but I
read somewhere that Python3 breaks the compatibility and a 2to3 fixer
can be used to fix open(). |
|
Date |
User |
Action |
Args |
2008-10-14 11:02:02 | vstinner | set | recipients:
+ vstinner |
2008-10-14 11:02:02 | vstinner | set | messageid: <1223982122.27.0.317312591734.issue4121@psf.upfronthosting.co.za> |
2008-10-14 11:02:01 | vstinner | link | issue4121 messages |
2008-10-14 11:02:00 | vstinner | create | |
|