我有一个模板文件:'template.txt'
如下所示:
class Core_Model_DbTable_{table_name} extends YouNet_Db_Table
{
const TYPE_PRINTED = 1;
const TYPE_DIGITAL = 2;
protected $_name = '{table_name}';
protected $_rowClass = 'Core_Model_{table_name:short}';
}
我使用Python 3.2读取该文件并尝试替换:
- {table_name} =>优惠券
- {table_name:short} =>优惠券
这里是我的代码:
in_file = open("template.txt","r")
text = in_file.read()
in_file.close()
txt = text.replace("{table_name}","Coupons")
txt = text.replace("{table_name:short}","Coupon")
但输出只显示结果:
c:\ Python32 \ python.exe builder.py
<?php
class Core_Model_DbTable_{table_name} extends YouNet_Db_Table
{
const TYPE_PRINTED = 1;
const TYPE_DIGITAL = 2;
protected $_name = '{table_name}';
protected $_rowClass = 'Core_Model_Coupon';
}
你能告诉我这里有什么问题吗?
答案 0 :(得分:4)
您似乎拼错了变量的名称:“txt”vs“text”。