1013 B
1013 B
#python
需求:检测文本的括号是否匹配:
举例说明,获得左括号的数量:
源码:
from inspect import getcomments
import os
from pickle import TRUE
from re import S
import sys
import json
import re
svnfile = open("./hotfix.txt",'r',encoding= "utf-8")
start = False
leftcount = 0
rightCount = 0
txt = ""
lalal = svnfile.readlines()
for i in range(len(lalal)):
line = lalal[i]
if(line.__contains__("regionstart")):
start = True
if(line.__contains__("regionend")):
start = False
if(start == True and "(" in line):
leftcount = leftcount + len(line.split('('))-1
if(start == True and ")" in line):
rightCount = rightCount + len(line.split(')'))-1
if(start == False):
if(leftcount == rightCount):
leftcount = 0
rightCount = 0
else:
print("leftcount:"+str(leftcount))
print("rightCount:"+str(rightCount))
print("txt:"+lalal[i])