一个简单的Python字符串处理文件

#!/usr/bin/env python3

import re

def lineprocess(line):
	res = ''
	index = 47
	if line[index] == 'e':
		index = index+2
	if line[index] == '=':
		index = index+1
	while True:
		if line[index] == 'm':
			break
		res = res+line[index]
		index = index+1
	return res

def main():
	index = 1
	text = open('data.txt', "r") # open()
	for line in text.readlines(): # readlines()
		res = lineprocess(line) # res => str
		#print(('%d '+res) % index)
		print(res)
		index = index+1

if __name__ == '__main__':
	main()

2017/3/6

posted @ 2017-03-06 23:56  Wasdns  阅读(166)  评论(0编辑  收藏  举报