parser = argparse.ArgumentParser()
parser.add_argument('-TNm', '--file1', type=argparse.FileType('r'), required=True)
parser.add_argument('-Css', '--file2', type=argparse.FileType('w'), required=True)
parser.add_argument('-Iacs', '--file3',type=argparse.FileType('w'), required=True)
args = parser.parse_args()
def main(args):
with open(args.file1) as TN, open(args.file2) as Cs, open(args.file3) as Ia:
for line in enumerate(TN):
.................... #processing each line and its indice
if __name__ == '__main__':
main(args)
我通过
运行此脚本python3 ~/script.py -TNm ~/file1 -Css ~/file2 -Iacs ~/file3
发生错误:
TypeError: invalid file: <_io.TextIOWrapper name='~/file1' mode='r' encoding='UTF-8'>
enumerate(TN)
有问题吗?