AttributeError: '_io.BufferedWriter' object has no attribute 'writer'

AttributeError: '_io.BufferedWriter' object has no attribute 'writer'

所以我的代码给出了错误:

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()