美文网首页
2022-06-28 python 处理数据

2022-06-28 python 处理数据

作者: Tomasmule | 来源:发表于2022-06-27 23:39 被阅读0次

python 3.6.8

import os
import sys
import subprocess
from subprocess import PIPE

argvs=sys.argv[1:]
print(argvs)
print("test.py turns eachturntimes firstthreshold")
truns=int(argvs[0])
eachTimes=int(argvs[1])
threshold=int(argvs[2])
path=os.getcwd()+"/main"
i = 0
totalVal=0
totaltimes=truns
while i < truns: 
    pipe = subprocess.Popen([path, str(eachTimes), str(threshold)], stdout=PIPE, bufsize=1)
    sub=0
    normal=1
    file = open(str(i) + ".txt", "w+")
    print("i times: " + str(i), flush=True)
    for info in iter(pipe.stdout.readline, b''):
        out=info.decode('utf-8')
        arr=out.split(" ")
        times = float(arr[1])
        val = float(arr[3])
        if val > threshold and sub == 0:
            pipe.kill()
            normal=0
            print("execpt " + out, flush=True)
        file.write(out)
        sub=sub+1
        if (times >= eachTimes):
            print("val " + str(val), flush=True);
            totalVal = totalVal + val
            pipe.kill()
    file.close()
    if normal:
        i=i+1
avg=totalVal/truns
print("avg is " + str(float(avg)))

相关文章

网友评论

      本文标题:2022-06-28 python 处理数据

      本文链接:https://www.haomeiwen.com/subject/nkttbrtx.html