我正在尝试使用以下查询来使用 AWS Translate API 获取翻译数据,但是我无法找到以.txt
格式保存结果的合适方法。
import boto3
data = 'file.txt'
translate = boto3.client(service_name='translate', region_name='us-east-1', use_ssl=True)
with open('file.txt', 'r') as text:data = text.read()
result = translate.translate_text(Text=data,
SourceLanguageCode="en", TargetLanguageCode="de")
print('TranslatedText: ' + result.get('TranslatedText'))
print('SourceLanguageCode: ' + result.get('SourceLanguageCode'))
print('TargetLanguageCode: ' + result.get('TargetLanguageCode'))
output = out_fun()
file = open("sample.txt","w")
file.write(output)
file.close()
我希望按照C:\Users\Ashish\Documents\Script