注:错误
# coding = utf-8
import re
with open('D://1/1.txt','r') as f:
line = f.read().strip()
result = re.split(r"[\s\n]", line)
# \s:从左往右 \n:换行
print(result)
D:\python\python.exe D:/pycharm/pythonfile/2021/ip_times.py
Traceback (most recent call last):
File "D:\pycharm\pythonfile\2021\ip_times.py", line 4, in <module>
line = f.read().strip()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xbd in position 23368: illegal multibyte sequence
Process finished with exit code 1
解决方法:加上encoding=‘utf-8’
# coding = utf-8
import re
with open('D://1/1.txt','r',encoding='utf-8') as f:
line = f.read().strip()
result = re.split(r"[\s\n]", line)
# \s:从左往右 \n:换行
print(result)