(文件)在try ... except塊我要記錄的異常錯誤消息,除了路徑中的文件。開放除了
try:
doc = etree.parse(urllib2.urlopen(url))
except Exception, e:
print '%s: %s' % (e, url)
with open('error.txt', 'a') as f:
f.write('%s:%s\n' % url, e)
return
打印顯示錯誤,但打開顯示... f.write不被執行。
在同一個腳本的relaxng驗證寫入文件
if not RELAXNG.validate(doc):
with open('error.txt', 'a') as f:
f.write('%s\n' % RELAXNG.error_log)
return
誰能給我解釋一下,爲什麼
with open('myfile.txt', 'a') as f
f.write(...
在如果聲明更多鈔票,而不是在一個除了?
考慮使用[記錄模塊(http://docs.python.org/2/howto/logging.html#basic-logging-tutorial) – 2013-03-07 12:26:55