Python Forum

Full Version: semantics of open(buffering=-1) ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
the library reference manual shows for open() that the keyword argument buffering= has a default value of -1. it does not explain what that means or does. is it a default indicator like None usually is?
The docs do say what happens when no value is passed for buffering, i.e. what the default behaviour is (which is what -1 corresponds to). The great thing about Python being open source is that you can go look at the source - it is left as an exercise for you to find the source for open and see what it does with that argument.
then, what is the point of there being that document if the source can be used? i think Python would not be as popular as it is if everyone needed to read the source to know how it all worked? source is good, but not for this.
Well the docs do tell you what the default behaviour is and that buffering should be an integer, which is really about as much as you need to know as a user. If you actually care why the default is -1 instead of None then yeah, you can look at the source to see what it's doing.
back when i coded in C, -1 was often used as "assume nothing" value, even where i could have done that with 0. getting an answer to "why?" probably does need to go to source. a useful document would be "Python Tricks and Hints". it would tell programs a lot of ways to make things work, including telling when using -1 or -1.0 works out better than None. i'm curious, but not urgently so. i'll probably look at the source next year.