python文件截取的方法
发布网友
发布时间:2022-04-27 03:00
我来回答
共4个回答
热心网友
时间:2022-04-07 13:09
import io
reader = open('test11.txt','r+',encoding = 'utf-8')
line = reader.readline()
user = []
while line != '' and line is not None:
user = line.split(' ')[0].split(':')[1]
print(user)
line = reader.readline()
reader.close()
热心网友
时间:2022-04-07 14:27
python里面有.split 方法,首先你line.find(:) 然后.split(" " )就可以了...
热心网友
时间:2022-04-07 16:01
for line in open('a.txt', 'r'):
line = line.split(' ')[0]
print(line.split(':')[1])
热心网友
时间:2022-04-07 17:53
正则表达式
import re
text = "time:0.0009 user:12312312312"
sub_text = re.match(r'time:(\S+).*',text)
print sub_text.group(1)