[Python-checkins] CVS: python/dist/src/Lib fileinput.py,1.4,1.5

Guido van Rossum python-dev@python.org
2000年4月10日 13:16:15 -0400 (EDT)


Update of /projects/cvsroot/python/dist/src/Lib
In directory eric:/projects/python/develop/guido/src/Lib
Modified Files:
	fileinput.py 
Log Message:
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.
Index: fileinput.py
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Lib/fileinput.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** fileinput.py	1999年10月18日 21:41:43	1.4
--- fileinput.py	2000年04月10日 17:16:12	1.5
***************
*** 78,82 ****
 _state = None
 
! def input(files=(), inplace=0, backup=""):
 global _state
 if _state and _state._file:
--- 78,82 ----
 _state = None
 
! def input(files=None, inplace=0, backup=""):
 global _state
 if _state and _state._file:
***************
*** 124,136 ****
 class FileInput:
 
! def __init__(self, files=(), inplace=0, backup=""):
 if type(files) == type(''):
 files = (files,)
 else:
! files = tuple(files)
 if not files:
! files = tuple(sys.argv[1:])
! if not files:
! files = ('-',)
 self._files = files
 self._inplace = inplace
--- 124,137 ----
 class FileInput:
 
! def __init__(self, files=None, inplace=0, backup=""):
 if type(files) == type(''):
 files = (files,)
 else:
! if files is None:
! files = sys.argv[1:]
 if not files:
! files = ('-',)
! else:
! files = tuple(files)
 self._files = files
 self._inplace = inplace

AltStyle によって変換されたページ (->オリジナル) /