import codecs, os, subprocess SRC = [ 'index', 'credits', 'prolog', 'intro', 'section_1', 'chapter_1', 'chapter_2', 'chapter_3', 'chapter_4', 'chapter_5', 'chapter_6', 'chapter_7', 'chapter_8', 'section_2', 'chapter_9', 'chapter_10', 'chapter_11', 'chapter_12', 'annex', 'credits_photo', ] OUT = 'ceibal' FILE_SEP = '\n\n\n^-^_^-^_^-^_^-^_^-^_^-^_^-^_^-^_\n\n\n' path_out_txt = os.path.join('tmp', '%s.txt' % OUT) with codecs.open(path_out_txt, 'wb', 'utf-8') as file_po: for name in SRC: path_src = os.path.join('source', 'es', '%s.rst' % name) with codecs.open(path_src, 'rb', 'utf-8') as file_src: file_po.write(file_src.read()) file_po.write(FILE_SEP) path_out_po = os.path.join('tmp', '%s.po' % OUT) subprocess.call('txt2po --encoding utf-8 %s %s' % (path_out_txt, path_out_po), shell=True)