为了账号安全,请及时绑定邮箱和手机立即绑定

执行到后面就死循环了,这是怎么回事啊?

执行到后面就死循环了,这是怎么回事啊?

jeck猫 2022-12-18 12:08:04
#!/usr/bin/python#Filename: bidui.py#_*_coding:utf-8_*_import glob, os, re ,os.path,datetime path_a = 'e:\\case\\' path_b = 'e:\\1\\'  a_files = glob.glob('%s\\*' % path_a) b_files = glob.glob('%s\\*' % path_b)flie3 = open('testresult.txt', 'a') # open for 'w'ritingfor f in a_files:file_name = os.path.basename(f) file_name_in_folder_b = re.subn(r'\d{8}_\d{2}_\d{2}_\d{2}_', '', file_name) full_path = '%s\\%s' % (path_b, file_name_in_folder_b)full_patha = '%s\\%s' % (path_a, file_name)print (file_name)if full_path in b_files:file_in_a = open(full_patha, 'r')line2 = file_in_a.readline()file_in_b = open(full_path, 'r')line = file_in_b.readline()while True:  if len(line) == 0 and len(line2) == 0: break  if line == line2:flie3.write('pass')else:print ('failed')flie3.write('fail')file_in_a.close()file_in_b.close()flie3.close()这是我写的一段文本比对程序 用了比对2个文件的内容的结果循环到 if line == line2:flie3.write('pass')
查看完整描述

2 回答

?
拉莫斯之舞

TA贡献1820条经验 获得超10个赞

if len(line) == 0 and len(line2) == 0: 
break  
==>
if len(line) == 0 or len(line2) == 0: 
break

查看完整回答
反对 回复 2022-12-21
?
喵喵时光机

TA贡献1846条经验 获得超7个赞

你写了while True了一定是个死循环~至少每个分支后面和close后面要break吧

查看完整回答
反对 回复 2022-12-21
  • 2 回答
  • 0 关注
  • 98 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信