slicing the end of a string in a list

Steven D'Aprano steve at REMOVETHIScyber.com.au
Fri Mar 3 05:27:30 EST 2006


On Fri, 03 Mar 2006 01:03:38 -0800, P Boy wrote:

> I had some issues while ago trying to open a large binary file.

The important term there is BINARY, not large. Many problems *reading*
(not opening) binary files will go away if you use 'rb', regardless of
whether they are small, medium or large.

> Anyway, from file() man page:
> 
> If mode is omitted, it defaults to 'r'. When opening a binary file, you
> should append 'b' to the mode value for improved portability. (It's
> useful even on systems which don't treat binary and text files
> differently, where it serves as documentation.) 

Which does not suggest that using 'rb' is better for large files and 'r'
for small. It suggests that using 'rb' is better for binary files and 'r'
for text.

> The optional bufsize
> argument specifies the file's desired buffer size: 0 means unbuffered,
> 1 means line buffered, any other positive value means use a buffer of
> (approximately) that size. A negative bufsize means to use the system
> default, which is usually line buffered for tty devices and fully
> buffered for other files. If omitted, the system default is used.2.3

If you are having problems with large files, changing the buffering will
help far more than changing the mode.


-- 
Steven.




More information about the Python-list mailing list