From 4c06bace406b72fb7b67247b613f256ac22060eb Mon Sep 17 00:00:00 2001 From: WangTsing-Yan Date: Sat, 11 May 2024 06:20:06 +0000 Subject: [PATCH] =?UTF-8?q?update=20=20common/file.py:=20if=5Fstr=5Fin=5Ff?= =?UTF-8?q?ile=20=E4=BD=BF=E7=94=A8=E4=BA=86=20Python=20=E7=9A=84=20any()?= =?UTF-8?q?=20=E5=87=BD=E6=95=B0=E9=85=8D=E5=90=88=20generator=20expressio?= =?UTF-8?q?n=20=E6=9D=A5=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9E=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=EF=BC=8C=E5=A6=82=E6=9E=9C=20dist=5Fstr=20=E5=9C=A8?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E4=BB=BB=E4=BD=95=E4=B8=80=E8=A1=8C?= =?UTF-8?q?=E4=B8=AD=E5=87=BA=E7=8E=B0=EF=BC=8Cany()=20=E4=BC=9A=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=20True=EF=BC=8C=E5=90=A6=E5=88=99=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=20False=E3=80=82=E8=BF=99=E6=A0=B7=E4=B8=8D=E4=BB=85=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=9B=B4=E7=AE=80=E6=B4=81=EF=BC=8C=E4=B9=9F=E5=87=8F?= =?UTF-8?q?=E5=B0=91=E4=BA=86=E6=98=BE=E5=BC=8F=E7=9A=84=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E5=92=8C=E8=AE=A1=E6=95=B0=E5=8F=98=E9=87=8F=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E5=BE=97=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=98=93=E4=BA=8E=E9=98=85?= =?UTF-8?q?=E8=AF=BB=E5=92=8C=E7=BB=B4=E6=8A=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: WangTsing-Yan --- common/file.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/common/file.py b/common/file.py index 2184699..8429223 100644 --- a/common/file.py +++ b/common/file.py @@ -58,15 +58,8 @@ class FileOperation: @staticmethod def if_str_in_file(file_name, dist_str): - i = 0 - with io.open(file_name,'r') as file: - for item in file.readlines(): - if dist_str in str(item): - i = i + 1 - if i != 0: - return True - else: - return False + with open(file_name, 'r') as file: + return any(dist_str in line for line in file) @staticmethod def get_str_num_in_file(file_name, dist_str): -- Gitee