問題:函數
google translate對於大文件不支持,咋辦?google
思路:本身寫個函數把的文件拆成小文件,再用google translate!spa
code:code
from googletrans import Translator import sys translator = Translator() fname=sys.argv[1] foname=fname + '-cn.txt' cont=open(fname).read() fdes = open(foname,'w') N=5000 i=0 L=len(cont) while i<L: print (1.0*i/L) i2 = min(i+N, L) subCont = cont[i:i2] s=(translator.translate(subCont, src='en', dest='zh-cn')) try: fdes.write(str(s.text)) except: pass i = i+N fdes.close()