读取行之间有\ n的txt文件

问题描述 投票:0回答:1

我有一个txt文件,其中包含不同档位的营业时间。

我正在尝试用python读取字典中的txt文件。

txt文件是这样的

鸡饭|周一至周五:08:30至17:00 \ n周六:09:00至15:00 \ n周日和公众假期:休息西餐|周一至周五:10:00至19:00 \ n周六,周日和PH:关闭]]

我尝试使用:

stalls = {}
with open("Operation Hour.txt") as f:
for line in f:
    (key, value) = line.split("| ")
    stalls[key] = value

但是结果不会拆分为新行。而是在输出中显示“ \ n”,这不是我想要的。

显示:

Chicken Rice     Mon - Fri: 08:30 to 17:00\n Sat: 09:00 to 15:00\n Sun & PH: Closed

而不是:

Chicken Rice     Mon - Fri: 08:00 to 19:00
                       Sat: 09:00 to 15:00
                       Sun & PH: Closed

请帮助我。谢谢。

我有一个txt文件,其中包含不同摊位的营业时间。我正在尝试在python中读取字典中的txt文件。 txt文件就是这样的Chicken Rice |周一-周五:08:...

python python-3.x tkinter
1个回答
0
投票

您可能必须自己实施。看一下这个答案。它可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.