Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2516b39

Browse files
committed
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.
1 parent b81e70e commit 2516b39

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

Lib/fileinput.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777

7878
_state = None
7979

80-
def input(files=(), inplace=0, backup=""):
80+
def input(files=None, inplace=0, backup=""):
8181
global _state
8282
if _state and _state._file:
8383
raise RuntimeError, "input() already active"
@@ -123,15 +123,16 @@ def isstdin():
123123

124124
class FileInput:
125125

126-
def __init__(self, files=(), inplace=0, backup=""):
126+
def __init__(self, files=None, inplace=0, backup=""):
127127
if type(files) == type(''):
128128
files = (files,)
129129
else:
130-
files = tuple(files)
130+
if files is None:
131+
files = sys.argv[1:]
131132
if not files:
132-
files = tuple(sys.argv[1:])
133-
if not files:
134-
files = ('-',)
133+
files = ('-',)
134+
else:
135+
files = tuple(files)
135136
self._files = files
136137
self._inplace = inplace
137138
self._backup = backup

0 commit comments

Comments
 (0)