我试图从强力球中奖号码文件阅读: http://www.powerball.com/powerball/winnums-text.txtPython的错误从文件缓冲区例如读取
我试图用线把它行,我有这样的代码:
import urllib.request
with urllib.request.urlopen("http://www.powerball.com/powerball/winnums-text.txt") as file:
next(file)
for line in file:
line.lstrip("b'")
line.rstrip(" \r\n'")
print(line)
文件中的每一行打印出来是这样的:
b'12/06/1997 15 26 28 08 43 36 \r\n'
b'12/03/1997 18 09 14 47 42 32 \r\n'
b'11/29/1997 11 27 13 02 31 23 \r\n'
b'11/26/1997 15 46 34 23 40 35 \r\n'
b'11/22/1997 22 31 03 07 14 02 \r\n'
我收到错误:
File "powerball.py", line 5, in <module>
line.lstrip("b'")
TypeError: 'str' does not support the buffer interface
我试图摆脱多余的字符,并作出这样的行:
12/06/1997 15 26 28 08 43 36
我该如何解决这个问题?
你能解释一下你正准备尝试修复什么,以及你想要的输出到底是什么? – idjaw
@idjaw我对帖子进行了更改 –