#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
file = sys.argv[1]
f = open(file, 'r')
prefix = None
for line in f:
# continue if line is empty
if not line.strip():
continue
# set prefix if it is not set and continue
if prefix is None:
prefix = line.strip()
continue
# unset prefix on given condition and continue
if line.startswith('*' + prefix):
prefix = None
continue
# if prefix is set and above does not apply print prefix plus line
if prefix is not None:
print(prefix + ' ' + line.strip())
f.close()
尝试以下操作,将txt文件作为第一个参数:
您可以使用:
相关问题 更多 >
编程相关推荐