- 论坛徽章:
- 5
|
本帖最后由 Linux_manne 于 2015-05-06 11:02 编辑
这样??
T1 包括2行 是指 缩进吗?如果是 可以这样:- f = open('1-500.txt','r')
- while True:
- current = f.readline()
- if current.startswith('TI'):
- after = f.readline()
- if after.startswith(' '):
- print current,after
- else:
- print current
- if current.startswith('RP'):
- print current
- if current.startswith('C1'):
- print current
复制代码 如果T1 下面缩进不止2行 用下面:- f = open('1-500.txt','r')
- while True:
- current = f.readline()
- if current.startswith('TI'):
- print current
- while True:
- after = f.readline()
- if after.startswith(' '):
- print after
- else:
- break
- if current.startswith('RP'):
- print current
- if current.startswith('C1'):
- print current
复制代码 |
|