所以我的代码给了我一个错误:
AttributeError: '_io.BufferedWriter' object has no attribute 'writer'
知道为什么吗? 这是我的密码:
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()
相关问题 更多 >
编程相关推荐