想学python很久了,一直在看,上次花半天写了个工具不能执行,一气之下用c++15分钟搞定。这次又有个写小工具的机会,终于搞定了,丑是丑了点,不过我还是看着很顺眼。中间用到了文件的一些操作,包括打开,读,写,查看文件在不在等等操作。
import os
import time
import glob
file_object = open('querylist.txt', 'r')
file_out = open('queryre.txt', 'w')
for eachLine in file_object:
print(eachLine)
eachLine = eachLine.strip('\n')
output = open('query.txt', 'w')
output.write(eachLine+os.linesep)
output.write('_end_')
output.close()
while(os.path.exists('query.txt')):
time.sleep(5)
filelist_not = glob.glob("./*.not.exists")
filelist_out = glob.glob("./*.out")
if (len(filelist_not) == 0 and len(filelist_out) == 1):
exis = 1
else:
exis = 0
if(len(filelist_not) > 0):
for delfile in filelist_not :
os.remove(delfile)
else:
for delfile in filelist_out :
os.remove(delfile)
outline = eachLine + ' ' + str(exis) + os.linesep
file_out.writelines(outline)
print(outline)
file_object.close()
file_out.close()