我正在尝试将.xslx和.csv(或用户为扩展名输入的任何内容)文件写出到它们值得尊重的文件中。正在使用的库称为tablib(关于此特定问题的文档很多)
到目前为止,已尝试打印出data.export('csv')函数的结果。效果很好,但没有要求。
def export(extension):
data = tablib.Dataset()
headers = ["Name","e-mail","location","address","contact"]
data.headers = headers
for line in lines: #this is referring to some extracted lines of code
data.append([Name,email,location,address,contact])
with open("bucket-objects/"+"ListS3"+'.csv', 'w') as f:
f.write(data+"."+extension)
理想的结果是成功创建文件,因为扩展名希望将其写出并保存到模块的父目录中。 任何帮助将不胜感激!