【发布时间】:2015-04-16 23:31:20
【问题描述】:
我想用lastrun 日期属性中的当前日期更新xml 文件。
下面的代码导致+ str(mprocessdate) +,我希望它说2015-04-16。
我的代码有什么问题?为什么我得到的是那个字符串而不是实际的日期?
company1.xml
<corp>
<lastrun date="20150123" />
<company id="18888802223">
<name>South Plantation</name>
<P_DNIS>99603</P_DNIS>
<Tracking_Phone>+18888802223</Tracking_Phone>
<Account>South Plantation</Account>
<AppendValue> Coupon</AppendValue>
<InsertCoupon>Y</InsertCoupon>
</company>
</corp>
脚本
import datetime
from xml.etree import ElementTree as ET
mprocessdate = datetime.date.today()
print (mprocessdate)
tree = ET.parse("company1.xml")
mlastrun = tree.find('lastrun')
mlastrun.set('date', '+ str(mprocessdate) + ')
tree.write('company.xml')
【问题讨论】:
-
你试过运行你的代码吗?当你这样做时会发生什么?
标签: python xml elementtree