柚子的collection

#!/usr/bin/env python
# coding=utf-8
# filename : calculate.py
# running  : python calculate.py destination_path
# author   : Chicho 
# data     : July 23, 2016 Saturday

import os
import sys,getopt

def usage():
    print "python calculate.py destination_path."


opts,args = getopt.getopt(sys.argv[1:], "h")

dest_path = ""

for op,value in opts:
    if op == "-h":
        usage()
        sys.exit()
    elif op == "":
        usage()
        sys.exit()
    else:
        dest_path = sys.argv[1]
        print dest_path

dest_path = sys.argv[1]


fileList = os.listdir(dest_path)

print fileList




for filename in fileList:
    if filename.endswith(".txt"):
        sequence = []
        temp = filename.split(".")
        t1 = temp[0] # e.g. on_50
        t2 = t1.split("_")
        version = t2[1]
        resultfilename = "result_" + version + ".txt"
        
        destFilePath = os.path.join(dest_path, filename)

        resultPath = os.path.join(dest_path,resultfilename)

        f = open(destFilePath)
        
        print destFilePath

        for line in f.readlines():
            info = line.split()
            num = info[-1] # get the last coloum
            sequence.append(num)
   
        

        f.close()

        numseq = [float(item) for item in sequence]

        avg = sum(numseq)/len(numseq)
    
        sdsq = sum([(i-avg)**2 for i in numseq])

        stdev = (sdsq/(len(numseq)-1))**0.5

        print avg,sdsq,stdev

        resultfile = open(resultPath,"w+")

        resultfile.write(str(avg) + "\n" + str(sdsq)+"\n" + str(stdev) + "\n")

        resultfile.close()
    
        print filename




今天也不知道为什么突然就难过了,未来还有家人要保护,还有很多精彩要我去挖掘。


我要做一个外表和内心都很nice的人。


加油好好学习,让自己每一天都变得更美好~


我要练出马甲线!!!


让大家都觉得和我在一起很舒服,加油啊,狗狗,柚子小姐~

生活不止诗与远方,还有傲娇的认真脸,


柚子的collection_第1张图片

你可能感兴趣的:(【实验数据脚本收集】)