m0_58248973
2021-06-22 10:46
采纳率: 40%
浏览 51

python多个字符串转列表

 我想将下面的转成列表形式:['NORTHWESTERN_UZBEKISTAN','UZ-1976-0001','19760517','025841','40.3516','63.4487','13.7','ISC']。哪位大神知道啊?

file_path='C:\\Users\\user\\Desktop\\shuju\\esm小样\\A.GZL..HNE.D.19760517.025841.C.ACC.txt'
with open(file_path) as f:
  for num, line in enumerate(f):
    if num <= 50:
      a = line.split(":")
      b = a[ 1 ]
      c = b.rstrip()
      print(c)

最后打印出:

 NORTHWESTERN_UZBEKISTAN
 UZ-1976-0001
 19760517
 025841
 40.3516
 63.4487
 13.7
 ISC
 6.7
 Kondorskaya_Ulomov_1996
 6.4
 Kondorskaya_Ulomov_1996
 TF
 A
 GZL
 Karakyr Point
 40.350000
 63.470000

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • robot8me 2021-06-22 11:00
    已采纳
    file_path='C:\\Users\\user\\Desktop\\shuju\\esm小样\\A.GZL..HNE.D.19760517.025841.C.ACC.txt'
    ls = []
    with open(file_path) as f:
      for num, line in enumerate(f):
        if num <= 50:
          a = line.split(":")
          b = a[ 1 ]
          c = b.rstrip()
          ls.append(c)  # 这里修改一下
    
    1 打赏 评论

相关推荐 更多相似问题