四川,中,成都市,028
四川,中,自贡市,0813
四川,中,泸州市,0830
四川,高,德阳市,0838
四川,中,绵阳市,0816
四川,中,遂宁市,0825
四川,中,内江市,0832
四川,高,南充市,0817
四川,中,宜宾市,0831
四川,中,广安市,0826
四川,中,达州市,0818
file = open(r'C:\Users\ZSIns15-5558\Desktop\keycode.txt', encoding='UTF-8')
lines = file.readlines()
ltall = []
lt0 = []
lt1 = []
for line in lines:
lt = line.rstrip('\n').split(',')
ltall.append(lt[3])
if lt[1] == '高':
lt0.append(lt[3])
if lt[1] == '中':
lt1.append(lt[3])
print('所有区号:')
print('keycode=(\'%s\')' % '\',\''.join(ltall))
print()
print('高等级区号:')
print('level_0=(\'%s\')' % '\',\''.join(lt0))
print()
print('中等级区号:')
print('level_1=(\'%s\')' % '\',\''.join(lt1))
所有区号:
keycode=('028','0813','0830','0838','0816','0825','0832','0817','0831','0826','0818')
高等级区号:
level_0=('0838','0817')
中等级区号:
level_1=('028','0813','0830','0816','0825','0832','0831','0826','0818')