类
FileInput
是实现;其方法
filename()
,
fileno()
,
lineno()
,
filelineno()
,
isfirstline()
,
isstdin()
,
nextfile()
and
close()
correspond to the functions of the same name in the module. In addition it is
iterable
and has a
readline()
method which returns the next input line. The sequence must be accessed in strictly sequential order; random access and
readline()
cannot be mixed.
采用
mode
you can specify which file mode will be passed to
open()
。它必须是某一
'r'
and
'rb'
.
The
openhook
, when given, must be a function that takes two arguments,
filename
and
mode
, and returns an accordingly opened file-like object. You cannot use
inplace
and
openhook
在一起。
You can specify
encoding
and
errors
that is passed to
open()
or
openhook
.
A
FileInput
实例可以用作上下文管理器在
with
语句。在此范例中,
input
被关闭后于
with
语句的退出,即使发生异常:
with FileInput(files=('spam.txt', 'eggs.txt')) as input:
process(input)
3.2 版改变:
可以用作上下文管理器。
3.8 版改变:
关键词参数
mode
and
openhook
现在是仅关键词。
3.10 版改变:
The keyword-only parameter
encoding
and
errors
are added.
3.11 版改变:
The
'rU'
and
'U'
modes and the
__getitem__()
method have been removed.