【问题标题】:How to view translated document from如何查看已翻译的文档
【发布时间】: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() 的东西或某种方法以将值作为字符串或其他可写数据类型返回。

标签: python google-translate


【解决方案1】:

通过以下代码,可以输出二进制文件。

with open('translated_file.txt', 'wb') as f:     
   f.write(response.document_translation.byte_stream_outputs[0])

【讨论】:

    猜你喜欢
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 2022-11-11
    • 2019-02-26
    • 2020-04-12
    相关资源
    最近更新 更多