Пример #1
0
def main():
    with open('example.py') as f:
        d = f.read()
    inss = get_instructions(d)
    for i in inss:
        print(i)
    c = Counter(x.opname for x in inss)
    print(c)
Пример #2
0
def print_stats(path):
    instructions = []
    total = [Counter(),Counter(),Counter(),Counter()] 
    
    for dirpath, dirnames, filenames in os.walk(path):
        for filename in filenames:
            if filename.endswith('.py') and '__' not in filename:
                print(filename)
                with open(dirpath + '/' + filename, encoding='utf8') as f:
                    ins = get_instructions(compile(f.read(), filename, 'exec'))
                    names = [x.opname for x in ins if 'IMPORT' not in x.opname]
                    total[0].update(names)
                    total[1].update(zip(names, names[1:]))
                    total[2].update(zip(names, names[1:], names[2:]))
                    total[3].update(zip(names, names[1:], names[2:], names[3:]))
                    instructions.extend(ins)
    with open('instructions.txt', 'w', encoding='utf8') as f:
        for i in instructions:
            print(i, file=f)
    for n in [0,1,2,3]:
        with open('statistics_{}.txt'.format(n+1), 'w', encoding='utf8') as f:
            for k, v in sorted(total[n].items(), key=lambda x: x[1], reverse=True):
                print(k, round(v/len(instructions), 3), v, sep='; ', file=f)
Пример #3
0
def print_instructions(f):
    inss = get_instructions(f)
    for i in inss:
        print(i)