sys.argv
#test.py
import sys
if __name__ == '__main__':
print(sys.argv[1:])
终端输入内容并查看接收到的参数
使用argparse
import argparse
if __name__ == '__main__':
#python .\excelcompare.py 发票列表1.xlsx 发票列表2.xlsx sheet1 sheet1 1 BC
# parser.add_argument('--rate',type=float,default=0.05, help='the rate of the label')
parser.add_argument('file1name',type=str,default='', help='the excel file1 fullname,[type str]')
parser.add_argument('file2name',type=str,default='', help='the excel file2 fullname,[type str]')
parser.add_argument('file1sht',type=str,default='sheet1', help='the excel file1 sheetname,[type str]')
parser.add_argument('file2sht',type=str,default='sheet1', help='the excel file2 sheetname,[type str]')
parser.add_argument('headmatch',type=int,default=1, help='the excel file2 sheetname,[type int]')
parser.add_argument('KeyColumns',type=list,default=[], help='the excel file2 sheetname,[type list]')
parser.add_argument('-savefilename',type=str,default='', help='save excel filename')
parser.add_argument('-savesheetname',type=str,default='', help='save excel file sheetname')
opt = parser.parse_args()
print(opt)
终端输入内容并查看参数
python .\excelcompare.py 发票列表1.xlsx 发票列表2.xlsx sheet1 sheet1 1 BC