2017-07-18 66 views

回答

0

回答我的問題? 我發現模板將提供答案,並使用pystache,因爲它看起來很簡單。最後

import pystache 
txt = open('pystachetempl.xml', 'r').read() 
doc = open('results.xml', 'wb') 

doc.write(pystache.render(txt, { 
    "questionname": "expon frac neg", 
    "latexquestion1": "frac{3{x}^{-3}}{{(3x)}^{2}}", 
    "tans1": "1/(3*x^5)" 
    }).encode('utf-8')) 

我無法從文件中讀取上下文,必須使用代碼中的替換值才能使其工作。