【发布时间】:2017-02-08 07:28:39
【问题描述】:
我是 Python 新手,但我有如下文本文件:
12345 | 6789 | abcd | efgh
我希望我的输出是 Like :
12345
6789
abcd
efgh
======================
我真的不知道剧本 但是我用那些函数 split() , strip() ,责备责备做了很多脚本
但我没能做到 所以我寻求帮助是有人可以的。
我将不胜感激。
with open('contacts_index1.txt') as f:
lines = f.read().splitlines("|")
【问题讨论】:
-
你得到的问题到底是什么错误?
-
真正的代码是:
f.readlines()然后循环遍历它们,在 '|' 上拆分 -
Traceback (most recent call last): File "C:\Users\TOSHIBA\Desktop\findme.py", line 4, in <module> r = f.read() File "C:\Users\TOSHIBA\AppData\Local\Programs\Python\Python35-32\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 529: character maps to <undefined>