파이썬에서 Google Translate API를 사용하여 전체 .txt
파일을 번역하려고합니다.Python에서 Google Translate API를 사용하여 전체 .txt 파일을 번역하는 방법은 무엇입니까?
기본 코드는 다음과 같습니다
print(service.translations().list(source='zh',
target='en',
q=['上海熙缘节能环保科技服务有限公司',
'广东宏德科技物业有限公司']).execute())
if __name__ == '__main__':
main()
는 .txt 파일을 변환 할 수 있도록
가 어떻게이 코드를 수정할 수 있습니다?
print(service.translations().list(source='zh', target='en', q= (line.rstrip() for line in open('file.txt')).execute())
내가 표현식을 참조하십시오
파일에서 텍스트를 읽는 방법을 묻고 있습니까? –
예 (중국어 문자 포함)이므로 파일은 UTF 또는 유니 코드 형식입니다. 기본 디코더는 cp1252입니다. – shj997
가능한 [Google 번역을 통해 번역 할 Python 스크립트] (http://stackoverflow.com/questions/9404628/python-script-to-translate-via-google-translate) –