Parsing 如何创建数据日志名后跟时间戳的.csv文件?Python 2.7.3

Parsing 如何创建数据日志名后跟时间戳的.csv文件?Python 2.7.3,parsing,csv,timestamp,Parsing,Csv,Timestamp,Python 2.7.3 您好,我正在编写一个代码来检索用户输入的文件名。在获得文件名之后,我想将其转换为一个.csv文件,文件名后面跟有当前日期的时间戳 例如: Prompt User: Create a title for a .csv file: User Entry: Logs Desired Output: Logs07302014-1:27PM.csv 代码: 错误消息: File "titlecsv.py" f = csv.writer(open([outFile], 'ab'

Python 2.7.3

您好,我正在编写一个代码来检索用户输入的文件名。在获得文件名之后,我想将其转换为一个.csv文件,文件名后面跟有当前日期的时间戳

例如:

Prompt User: Create a title for a .csv file: 
User Entry: Logs
Desired Output: Logs07302014-1:27PM.csv
代码:

错误消息:

File "titlecsv.py"
f = csv.writer(open([outFile], 'ab'), delimiter=",", quotechar=" ",quoting=cv.QUOTE_MINIMAL)
TypeError: coercing to Unicode: need string or buffer, list found
我知道输出文件只能包含一个字符串。我不知道如何使我想要的输出文件成为当前代码中的一个字符串

打印输出文件进行调试时,它会显示一个列表:

['title','timestamp'] 
但是它应该是一个字符串,而不是一个分裂的字符串。我该如何解决这个问题

更新:当我使用f=open而不是f=csv.writer时,这会起作用,但我想这样做,以防将来必须将数据添加到excel文件中。是否有其他命令,如f.writerow,而不使用csv.writer

解决方案:

import time

title = raw_input("Create a title for a .csv file: ")

current_time = time.strftime("%m.%d.%y-%H%MPM.csv", time.localtime())
logname = title + '%s' %current_time

outFile = ''.join(logname) #combines list to a string

f = csv.writer(open(outFile, 'ab'),delimiter=",", quotechar=" ", quoting=csv.QUOTE_MINIMAL) #Create the .csv file with the string as the name

你有语法错误。outFile=title+'%s'%current\u time逗号或+符号对我仍然有效。不过我会把它改成+的。除此之外,我仍然有相同的错误消息。Update,当我使用f=open而不是f=csv.writer时,这会起作用,但我希望在将来必须将数据添加到excel文件中时可以这样做。是否有其他命令,如f.writerow,而不使用csv.writer?
import time

title = raw_input("Create a title for a .csv file: ")

current_time = time.strftime("%m.%d.%y-%H%MPM.csv", time.localtime())
logname = title + '%s' %current_time

outFile = ''.join(logname) #combines list to a string

f = csv.writer(open(outFile, 'ab'),delimiter=",", quotechar=" ", quoting=csv.QUOTE_MINIMAL) #Create the .csv file with the string as the name