【问题标题】:unneccassary \r in python dict keyspython dict键中不必要的\ r
【发布时间】:2022-06-14 17:11:15
【问题描述】:

我有一个txt 文件

-A
--this is for A1
--not just start with 2
--A3
-B
--B1
-C
--See1
--Yahoo

我希望这个txt文件的数据变成pythondict

喜欢

{
'A':['this is for A1', 'not just start with 2', 'A3'],
'B':['B1'],
'C':['See1', 'Yahoo']
}

我可以改变这个,但结果 dict 就像

{
'A\r':['this is for A1', 'not just start with 2', 'A3'],
'B\r':['B1'],
'C\r':['See1', 'Yahoo']
}

键中有一个额外的\r

我该如何解决这个问题?

【问题讨论】:

  • 请包含用于将.txt 文件转换为您的字典的代码。那里可能有一个错误导致额外的\r
  • 在 Windows 上,由于历史原因,行以 \r\n 而不是 \n 像许多其他操作系统一样终止。这可能与问题有关吗?

标签: python


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-27
  • 1970-01-01
相关资源
最近更新 更多