如果数组 len 计数等于文本文件行计数,如何编码 python 以获得打印

how to code python to get a print if the array len count equal to text file lines count

我的数组中有 10 个数组,numbers.txt 文件中有 10 行数字。

如何在 python 中编写代码,如果我的数组长度和文本文件行数相等,我需要得到一个 print("The process completed"),然后我需要打印一条消息。

数组:

number = [124,589,478,547,745,256,321,654,665,888]

文本文件:numbers.txt

124
589
478
547
745
256
321
654
665
888

在这里如果你只是想检查长度,你可以像下面那样做。

number = [124,589,478,547,745,256,321,654,665,888]
f = open('numbers.txt','r')
if len(number) == len(f.readlines()):
    print("The process completed")

这是获得你想要的东西的方法之一:

number = [124,589,478,547,745,256,321,654,665,888]
with open('numbers.txt','r') as f:
    if len(number) == len(f.readlines()):
        print("The process completed")
    else:
        print("The process is not yet completed")