python怎样从text file里读取数量?

比方说现在需要import一个file。
然后从里读出一共有几个两位数字,然后把两位数的个数print出来。
例如:file如下:
01
02
03
04
05
06
需要print出下面的output。该怎么做呢?

img

with open('tablefile.txt', 'r') as f:
    nums = f.readlines()

count = 0
for num in nums:
    if int(num.strip()) >= 10:
        count += 1

print("2位数个数为:", count)

count = 0
path = input("Table file\n")
with open(path, 'r') as f:
    for one in f.readlines:
        if len(one.strip()) == 2:
            count += 1
print("Imported {} table(s)".format(count))
    

给个例子,仅供参考:

with open('tablefile.txt','r') as f:
    lines = f.readlines()
    nums = len([line for line in lines if len(line.strip())==2])
    print(f"Table file:\ntablefile.txt")
    print(f'Imported {nums} table(s)')
    f.close()

img

test.txt 文本内容

asdfsafasdf01wqerqwrqwr
asdfsaf02
dfswqfqwe03fsadfafsafsaf
wqerqwr04ewrqwerqwer
qwer05asdfsadfsgsfg
qwerqwr06

import re


# 匹配数字, 并且是两位的
m = re.compile(r"\d{2}")

# 读取文本
with open("./test.txt", "r", encoding="utf8") as f:

    # 将所有2位数写入列表
    find_numbers = m.findall(f.read())
    print(find_numbers)

    # 列表的长度即两位数字个数
    count = len(find_numbers)
    print(f"一共有{count}个两位数字")
['01', '02', '03', '04', '05', '06']
一共有62位数字