标签:def strip readline with pre split encoding \n exit
#!/url/bin/env python #encoding=utf-8 #横杠为空置 def pao(num): if num in range(0,125): flag = "" with open(‘diqu.txt‘, ‘r‘) as f: for i in f.readlines(): data = i.strip() if data == ‘‘: flag += ‘-|‘ else: flag += data + "|" if num in range(0,15): diqu = "贵阳 " if num in range(15,33): diqu = "遵义 " if num in range(33,43): diqu = "安顺 " if num in range(43,59): diqu = "黔南 " if num in range(59,79): diqu = "黔东南 " if num in range(79,93): diqu = "铜仁 " if num in range(93,105): diqu = "毕节 " if num in range(105,113): diqu = "六盘水 " if num in range(113,126): diqu = "黔西南 " return(diqu + flag.split("|")[num]) if num in range(129,131): return("None") if num in range(135, 189): return("None") if num in range(201, 210): return("None") if num in range(234,241): return("None") if num in range(245,248): return("None") if num == 198 or num == 199 or num == 213 or num == 216 or num == 231 or num == 232 or num ==242 or num == 243: return("None") else:return("其他") def hander(string): ip = int(string.split(‘.‘)[2]) return(ip) count = -1 with open(‘ip.txt‘,‘r‘) as f: count +=1 if count == 125:exit() ip = f.readlines() for i in ip: ip = i.strip(‘\n‘) num = hander(ip) print(pao(num))
标签:def strip readline with pre split encoding \n exit
原文地址:https://www.cnblogs.com/nul1/p/10278938.html