在python中我可以写
content = open(filename, 'r').read()
将整个文件读入content
变量。但是,在我的装有 Python 2.7.5 的 Windows 机器上,对于一些大文件,这只读取 255 个字节。仔细查看 file.read 的文档会发现,只能期望以阻塞模式读取整个文件。如何启用阻塞模式以确保读取整个文件?
read(...)
read([size]) -> read at most size bytes, returned as a string.
If the size argument is negative or omitted, read until EOF is reached.
Notice that when in non-blocking mode, less data than what was requested
may be returned, even if no size parameter was given.