Don't empty the file when it is supposed to be only read.

Iterating over an fileinput.input() object with inplace=True
and not returning any results per iteration leaves an empty
input file.
Merge pull request #18682 from eliasp/2014.7-modules.file.replace-issue-18680

Don't empty the file when it is supposed to be only read.