这是非常simple.I敢肯定,我失去了一些东西愚蠢。蟒蛇如何从string.template对象转换为字符串
fp = open(r'D:\UserManagement\invitationTemplate.html', 'rb')
html = Template(fp.read())
fp.close()
html.safe_substitute(toFirstName='jibin',fromFirstName='Vishnu')
print html
当我直接在intepreter中运行此代码时,我得到正确的输出。 但是,当我从一个file.I运行它得到<string.Template object at 0x012D33B0>
。怎么我从string.Template对象转换为string.I试图str(html)
。通过再见不是print语句应该这样做(字符串转换)?