AttributeError: 'builtin_function_or_method' object has no attribute 'split' 3.7
AttributeError: 'builtin_function_or_method' object has no attribute 'split' 3.7
我需要帮助来修复此代码:
import urllib.request,urllib.parse,urllib.error
fhand = urllib.request.urlopen("http://data.pr4e.org//romeo.txt")
counts = dict ()
for line in fhand:
lines = line.decode.split()
for words in lines:
counts[words] = counts.get(words,0)+1
print(counts)
我在 运行 此代码时遇到此错误:
C:\Users\g.p\AppData\Local\Programs\Python\Python37-32>py urllib2.py
Traceback (most recent call last):
File "urllib2.py", line 5, in <module>
lines = line.decode.split()
AttributeError: 'builtin_function_or_method' object has no attribute 'split'
你应该 运行 decode
函数,否则,它将是内置函数而不是 str
,所以你不能 split
函数
你应该这样写:
lines = line.decode().split()
更多信息:Link
我需要帮助来修复此代码:
import urllib.request,urllib.parse,urllib.error
fhand = urllib.request.urlopen("http://data.pr4e.org//romeo.txt")
counts = dict ()
for line in fhand:
lines = line.decode.split()
for words in lines:
counts[words] = counts.get(words,0)+1
print(counts)
我在 运行 此代码时遇到此错误:
C:\Users\g.p\AppData\Local\Programs\Python\Python37-32>py urllib2.py
Traceback (most recent call last):
File "urllib2.py", line 5, in <module>
lines = line.decode.split()
AttributeError: 'builtin_function_or_method' object has no attribute 'split'
你应该 运行 decode
函数,否则,它将是内置函数而不是 str
,所以你不能 split
函数
你应该这样写:
lines = line.decode().split()
更多信息:Link