If you had a function that took a handler to a file and then performed some actions that moved the pointer, would you expect it to put the pointer back when it was finished? Additionally, would you generally expect it to rewind to the start before it began its work?
def hash_contents(fp): original_pos = fp.tell() fp.seek(0) # do hashing / whatever fp.seek(original_pos)
I've looked around a little to see what the most common assumptions are but I'm not sure what a good rule to follow is. For example,
shutil.copyfileobj copies from whatever position the file started in and then consumes to the end.
What are the pros / cons and are there any standard rules of thumb to follow when designing these sort of functions?
This is actually a subquestion of something I was asking over at StackOverflow (Prefer BytesIO or bytes for internal interface in Python?) that really seems more suitable over here.