配置文件和方差计算,读文件


读配置文件
    import ConfigParser
    config = ConfigParser.RawConfigParser()
    config.read(pconf)
    combine = config.getboolean('default', 'combine')
    filter = config.getboolean('default', 'filter')
    distinct = config.getboolean('default', 'distinct')
    src = config.get('default','src')
    dst = config.get('default','dst')
    pattern =  config.get('default','pattern')
    delta = config.getint('default', 'times')



      #second level filter
        total = sum( o for o in rtlist)
        avg = float(total) / x
        delta = math.sqrt(sum( math.pow((avg-o),2) for o in rtlist ) / (x - 1))

        result = []
        idx = 0
        count = 0
        total = 0
        for o in rtlist:
            if (avg - self.times * delta) <= o and o<= (avg + self.times * delta):
                result.append(data[idx])
                total += o
                count += 1
            idx += 1



列出所有文件
    def allfiles(self,root, patterns='*', single_level=False, yield_folders=False):
        # Expand patterns from semicolon-separated string to list
        patterns = patterns.split(';')
        for path, subdirs, files in os.walk(root):
            if yield_folders:
                files.extend(subdirs)
            files.sort( )
            for name in files:
                for pattern in patterns:
                    if fnmatch.fnmatch(name, pattern):
                        yield os.path.join(path, name)
                        break
            if single_level:
                break

你可能感兴趣的:(OS)