我的文本文件
import sys
from itertools import islice
args = sys.argv
print (args)
#['file.py','datafile','-N','10']
if args[1] == '-h':
print ("-N for printing the number of lines: python file.py datafile -N 10")
if args[2] == '-N':
datafile = args[1]
number = int(args[3])
with open(datafile) as myfile:
head = list(islice(myfile,number))
head = [item.strip() for item in head]
print (head)
print ('\n'.join(head))
用户期望的输入: 1)生成的行数
2)输出到文件或控制台
3)当没有给程序参数时提供帮助。
4)确保该程序生成的行数是该程序的用户输入的行数。 (想想很多)
python3 test.py --help(应该显示帮助选项)
python3 test.py -N 20型控制台(它应该在控制台中打印日志)
python3 test.py -N 10 -type日志-name abc.log(应该将日志打印到文件中)
我的Psedo代码
argument passing
还有没有比$I->grabService('doctrine');