【发布时间】:2021-10-18 21:19:53
【问题描述】:
我正在使用谷歌云翻译 api 翻译文档。见here。
在文档中,它说“要查看已翻译的文档,请将response.document_translation.byte_stream_outputs 写入文件”。但我不明白该怎么做?有人知道怎么做吗?
编辑—— 简单的代码如
with open('translated_file.txt', 'wb') as f:
f.write(response.document_translation.byte_stream_outputs)
给出以下错误“需要一个类似字节的对象,而不是'重复'”。
特别是 response.document_translation.byte_stream_outputs 的类型为 marshal.collections.repeated.Repeated
【问题讨论】:
-
这可能与将任何其他内容写入文件相同。你试过
with open('translated_file.txt', 'wb') as f: f.write(response.document_translation.byte_stream_outputs) -
@chickitychinachinesechicken 不起作用,请参阅我的编辑。
-
也许检查对象有哪些公共方法:
dir(response.document_translation.byte_stream_outputs),寻找类似_str()的东西或某种方法以将值作为字符串或其他可写数据类型返回。