python 计算结构数量

本文介绍了如何使用Python来计算各种结构的数量。通过示例代码,详细解析了在编程中统计结构实例的过程,帮助读者理解Python在处理数据结构计数上的应用。
摘要由CSDN通过智能技术生成
import os
import re
import sys

def extract(pattern1, str0):
    result1 = pattern1.findall(str0)
    str = ""
    if (result1):
        str = result1[0]
    return str

def ExtractVariablesFromFile (sourceFileStr, resultFileStr):
    sourceFile = open(sourceFileStr, mode='r', encoding='gbk')
    resultFile = open(resultFileStr, "w")
    pattern1 = re.compile(r'}[ ]*(\w+)')
    string = ""
    for line in sourceFile:
        string = extract(pattern1, line)
        if(string == ""):
            continue
        num = count(sourceFileStr, string)
        resultFile.write(string + " ")
        resultFile.write(str(num))
        resultFile.write("\n")
    sourceFile.close()
    resultFile.close()
def count(sourceFileStr, str):
    sourceFile = open(sourceFileStr, mode='r', encoding='gbk')
    position = sourceFile.te
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值