我尝试使用Python的csv和tempfile工具制作csv文件。我声明如下:
csvattachment = tempfile.NamedTemporaryFile(suffix='.csv', prefix=('student_' + studentID), delete=False)
with open(csvattachment.name, 'w+') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',')
filewriter.writerow([ #WRITE CONTENT HERE])
我接下来要做的就是附加这个文件并发送出去。问题在于,附件名不是“student_.csv”,而是更难看的东西,比如<tempfile._TemporaryFileWrapper object at 0x10cbf5e48>
NamedTemporaryFile()
类已经返回一个打开的文件,您不必重新打开它相关问题 更多 >
编程相关推荐