python 调用grep
#因为我现在还有找到在大量文件查找python实现的好方法。
#实现采用了grep的方法。
#使用了os.popen而不是subprocess中的Popen,因为前者的参数更简单
#不知subprocess中的Popen是否有更好的地方?
#gtalk: xurongzhong#gmail.com
import re
import time
import random
import sys
import os
for line in open("smu.csv"):
line = line.strip()
attr = line.split(',')
docid = attr[0]
isu_spam_rank = attr[1]
isu_quality_rank = attr[2]
isu_PornRank = attr[3]
isu_PoliticRank = attr[4]
strings = "grep " + docid + " spamRank.20.dat.csv"
f = os.popen(strings)
data = f.readline()
f.close()
if data :
value = data.strip().split(',')[1]
if int(value) == int(isu_spam_rank):
pass
else:
print docid +"**value**isu_spam_rank**" + value + "--------" + isu_spam_rank
print "error"
#实现采用了grep的方法。
#使用了os.popen而不是subprocess中的Popen,因为前者的参数更简单
#不知subprocess中的Popen是否有更好的地方?
#gtalk: xurongzhong#gmail.com
import re
import time
import random
import sys
import os
for line in open("smu.csv"):
line = line.strip()
attr = line.split(',')
docid = attr[0]
isu_spam_rank = attr[1]
isu_quality_rank = attr[2]
isu_PornRank = attr[3]
isu_PoliticRank = attr[4]
strings = "grep " + docid + " spamRank.20.dat.csv"
f = os.popen(strings)
data = f.readline()
f.close()
if data :
value = data.strip().split(',')[1]
if int(value) == int(isu_spam_rank):
pass
else:
print docid +"**value**isu_spam_rank**" + value + "--------" + isu_spam_rank
print "error"
相关文章