Skip to content

Commit

Permalink
Implement suggestion from Lawrence Kesteloot in PR#280, to change the
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gvanrossum committed Apr 10, 2000
1 parent b81e70e commit 2516b39
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Lib/fileinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

_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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2516b39

Please sign in to comment.