python - summary with code on fileinput module
1466 ワード
Topic: python - summary with code on fileinput module
the fileinput modules is the module which can take cares of the processing files from the command line of input from one or more files. it is common used in scripting where you have a set of files and you want to process them in a streaming line manner.
it automatically read the command line arguments ( out of sys.argv) and takes them as its input file. It allows you to then sequentially iterate through these lines.
Le's see some code.
the fileinput modules is the module which can take cares of the processing files from the command line of input from one or more files. it is common used in scripting where you have a set of files and you want to process them in a streaming line manner.
it automatically read the command line arguments ( out of sys.argv) and takes them as its input file. It allows you to then sequentially iterate through these lines.
Le's see some code.
'''
Created on 2012-11-7
@author: Administrator
file: FileInputModule.py
description: FileInputModule.py helps to demonstrate the use of fileinput module, the fileinput module support processing lines of input from one or more files.
'''
import fileinput
def main():
for line in fileinput.input():
if not line.startswith("#"):
print(line, end = " ")
if __name__ == '__main__':
print('we are going to examine the content of ... .... ')
main()
# to test the program, you can run with the following input line.
#> python FileInputModule.py txt1.tst txt2.tst
if you run the code, with the following command line. FileInputModule.py ..\..\Modules\ModuleNamespace.py
then you will see the contents of FileInputModule.py and the ModuleNamespace.py file with the comment line stripped out.