import reimport ioimport sysinput_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')s = input_stream.readlines()s = "\n".join(s)pc = '(//.*...
分类:
其他好文 时间:
2015-06-03 08:25:20
阅读次数:
1717
python读取文件内容时,有三种方法:read()、readline()和readlines()这三种方法区别如下:read(...)
read([size])->readatmostsizebytes,returnedasastring.
Ifthesizeargumentisnegativeoromitted,readuntilEOFisreached.
Noticethatwheninnon-blockingmode,lessdatathan..
分类:
编程语言 时间:
2015-05-29 18:29:07
阅读次数:
188
common.go ``` // copy code from github.com/shirou/gopsutil package sys import ( "bufio" "os" "strings" ) // ReadLines reads contents from file and splits them by new line. // A convenience wrapper ...
分类:
其他好文 时间:
2015-05-21 09:19:30
阅读次数:
280
接上一篇的日志格式,我们已经筛选出了所有的IP地址、做法稍有不同。nginx正则把IP写进文件里、还是那句话数据太大我们不能写进列表里边:defgetIP():
f=open(log,‘r‘)
IPdic={}
forloglineinf.readlines():
matchs=p.match(logline)
ifmatchs!=None:
allGroups=matchs.groups(..
分类:
其他好文 时间:
2015-05-20 18:53:07
阅读次数:
181
s3=set()
#s3=set(open(‘/home/work/ctt/20150409.uid.head‘,‘r‘).readlines())
file=open(‘/home/work/ctt/20150409.uid.head‘)
for?line?in?file.readlines():
???line=line.strip(‘\n‘)
#???print?l...
分类:
编程语言 时间:
2015-05-05 22:06:43
阅读次数:
156
file=open(‘lock.txt‘).readlines()name=input(‘username:‘).strip()lock=[]foriinfile:line=i.strip(‘\n‘)lock.append(line)ifnameinlock:print(name,‘已经被锁定,请联系开户行.退出!‘)else:i=1whilei<=3:i=i+1print(‘........................‘)username=nameprint(userna..
分类:
编程语言 时间:
2015-04-29 17:38:18
阅读次数:
587
最近用到python来处理文本文件了,然后需要处理文件。发现python中提供的with open as 这个还是用的不错的!好的,废话不多说了,看下例子:
with open('./sigir_title_cizu.txt') as cizu, open('sigir_title.txt') as titles:
cizuData = cizu.readlines()
title...
分类:
编程语言 时间:
2015-04-24 09:19:56
阅读次数:
841
代码函数import hashlibdef md5(str):
m = hashlib.md5()
m.update(str)
return m.hexdigest()f = open('idfa.csv','r')
result = open('test.csv','w')
for line in f.readlines():
encrypt...
分类:
编程语言 时间:
2015-04-22 14:00:05
阅读次数:
180
#!/usr/bin/envpython
#coding=utf-8
importstring
alist=[]
lease_IP=‘‘
lease_start=‘‘
lease_end=‘‘
istatus=‘‘
MAC=‘‘
f=open(‘/var/lib/dhcpd/dhcpd.leases‘)
lines=f.readlines()
f.close()
forlineinlines:
ifline.find(‘lease‘)<>-1:
lease_IP=line.split(‘\n‘)[..
分类:
其他好文 时间:
2015-04-20 18:49:48
阅读次数:
161
#!/usr/bin#coding:utf-8import os, re, errnols = os.popen('ls *.log').readlines()dirs = []lines = []for line in ls: if line.strip(): dirs.append(re....
分类:
Web程序 时间:
2015-03-10 15:27:20
阅读次数:
281