【发布时间】:2017-06-02 23:28:08
【问题描述】:
这是我正在使用的 DeathByCaptcha API 文档的引用。
dict deathbycaptcha.Client.decode(file imageFile, int timeout)
dict deathbycaptcha.Client.decode(str imageFileName, int timeout)
它可以接受图像文件的路径或文件对象
我有这行代码。
client.decode(urllib.urlopen('https://example/image.jpg').read(), 30)
但它给了我错误,因为 .read() 确实返回 file-like 对象。
我的偏好是在一行中完成。
有什么方法可以轻松地将read() 读取的流转换为类文件对象?
如果不能像我们在 PHP (string) 100 中那样在一行中做,那么我将接受多行
【问题讨论】:
-
您希望它是单行代码,以便您的代码简洁易读吗?如果是这样,您可以创建一个从 URL 读取并返回文件对象的函数。
-
标签: python python-2.7 file