- 論壇徽章:
- 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
復(fù)制代碼 如果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
復(fù)制代碼 |
|