- 论坛徽章:
- 4
|
本帖最后由 mswsg 于 2016-04-27 09:58 编辑
python remove_last_to_first.py --input your_input_file > output.txt- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- __author__ = 'shengwei ma'
- __author_email__ = 'shengweima@icloud.com'
- import sys
- import getopt
- input_file = ""
- try:
- opts, args = getopt.getopt(sys.argv[1:], "h", ["input="])
- except getopt.GetoptError as err:
- print(str(err))
- for op, value in opts:
- if op == "--input":
- input_file = value
- elif op == "-h":
- print("python remove_last_to_first.py --input your_input_file > out.txt")
- sys.exit()
- with open(input_file, 'r') as f:
- lines = f.readlines()
- print lines[-1].strip()
- for line in lines[:-1]:
- line = line.strip()
- print line
复制代码 |
|