diff options
author | Guido van Rossum <guido@python.org> | 2000-04-10 17:16:12 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-04-10 17:16:12 (GMT) |
commit | 2516b39dd35a3e0d815e25ee652cea6c90cc5b28 (patch) | |
tree | 5a1b19588e911510e4515ed08b13704cab962074 /Lib | |
parent | b81e70ebdb28246e427249d386518bc03d08c959 (diff) | |
download | cpython-2516b39dd35a3e0d815e25ee652cea6c90cc5b28.zip cpython-2516b39dd35a3e0d815e25ee652cea6c90cc5b28.tar.gz cpython-2516b39dd35a3e0d815e25ee652cea6c90cc5b28.tar.bz2 |
Implement suggestion from Lawrence Kesteloot in PR#280, to change the
default list of files from () to None, and explicitly test for None
before defaulting to sys.argv[1:]. This means that if you pass in an
explicit empty list, it will read stdin instead of defaulting to
sys.argv[1:]. This fixes a buglet in the test script (when called
with options but without files, it chokes when it tries to interpret
the options as files).
Lawrence adds: "I suspect that this is a safe change, because I can't
imagine someone actively passing in an empty list when they want
sys.argv used."
I agree.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/fileinput.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/fileinput.py b/Lib/fileinput.py index 8f73fad..d1b7617 100644 --- a/Lib/fileinput.py +++ b/Lib/fileinput.py @@ -77,7 +77,7 @@ import sys, os, stat _state = None -def input(files=(), inplace=0, backup=""): +def input(files=None, inplace=0, backup=""): global _state if _state and _state._file: raise RuntimeError, "input() already active" @@ -123,15 +123,16 @@ def isstdin(): class FileInput: - def __init__(self, files=(), inplace=0, backup=""): + def __init__(self, files=None, inplace=0, backup=""): if type(files) == type(''): files = (files,) else: - files = tuple(files) + if files is None: + files = sys.argv[1:] if not files: - files = tuple(sys.argv[1:]) - if not files: - files = ('-',) + files = ('-',) + else: + files = tuple(files) self._files = files self._inplace = inplace self._backup = backup |