Home > Backend Development > Python Tutorial > python命令行参数sys.argv使用示例

python命令行参数sys.argv使用示例

WBOY
Release: 2016-06-16 08:45:22
Original
1531 people have browsed it

复制代码 代码如下:

#diff.py
#!/bin/env python

import sys
if len(sys.argv) 3:
    print "Usage: " + sys.argv[0] + "file1 file2"
    sys.exit(-1)

file1 = sys.argv[1]
file2 = sys.argv[2]

list1 = {}
for line in open(file1):
    list1[line.split()[0]] = 1

for line in open(file2):
    key = line.split()[0]
    if key not in list1:
        sys.stdout.write(line)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template