Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:'_io.BufferedWriter';对象没有属性';作家';_Python_Attributeerror_Writer - Fatal编程技术网

Python 属性错误:'_io.BufferedWriter';对象没有属性';作家';

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

所以我的代码给了我一个错误:

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

这是一个输入错误,应该关闭。