Python 属性错误:'_io.BufferedWriter';对象没有属性';作家';
所以我的代码给了我一个错误: AttributeError:“\u io.BufferedWriter”对象没有属性“writer” 知道为什么吗? 这是我的密码:Python 属性错误:'_io.BufferedWriter';对象没有属性';作家';,python,attributeerror,writer,Python,Attributeerror,Writer,所以我的代码给了我一个错误: AttributeError:“\u io.BufferedWriter”对象没有属性“writer” 知道为什么吗? 这是我的密码: import requests import time import sys start = time.perf_counter() flags = open('flags.txt', 'r') countryCode = [] totalBytes = 0 for line in flags.readlines():
import requests
import time
import sys
start = time.perf_counter()
flags = open('flags.txt', 'r')
countryCode = []
totalBytes = 0
for line in flags.readlines():
countryCode.append(line.strip())
for country in countryCode:
url = f"https://www.cia.gov/library/pulications/resources/the-world-factbook/graphics/flags/large/{country}-lgflag.gif"
r = requests.get(url)
with open(f"{country}Flag.gif", 'wb') as f:
f.writer(r.content)
totalBytes+= sys.getsizeof(f)
end = time.perf_counter()
print ("elapsed time:", end - start)
print (totalBytes, "bytes dowloaded")
谢谢。文件对象(f
)没有任何名为writer
的方法
相反,使用
f.write()
这是一个输入错误,应该关闭。