【发布时间】:2019-02-12 18:17:07
【问题描述】:
这是我将输出保存到csv 文件的脚本:
import os, csv, datefinder, datetime
os.chdir('C:\Users\dul\Desktop\Article')
with open("test2.txt", 'r') as file1:
text1 = file1.read()
matches = list(datefinder.find_dates(text1))
if len(matches) > 0:
date = matches[1]
print date
else:
print 'No dates found'
csv = open(date, "w")
columnTitleRow = "date, time\n"
csv.write(columnTitleRow)
当我运行此脚本时,我收到以下错误消息:
[回溯(最近一次通话最后一次): 文件“C:\Users\dul\Desktop\Article\ap.py”,第 18 行,在 csv = open(date, "w") TypeError: coercing to Unicode: need string or buffer, datetime.datetime found]
【问题讨论】:
-
下次请将完整的错误堆栈跟踪添加到您的问题中。这有助于我们查看错误发生在哪一行以及哪个底层函数引发了错误。
-
@Ralf 好的。谢谢你告诉我!
标签: python