将打印输出重定向到csv文件的问题?

时间:2019-07-19 14:43:07

标签: python list csv tuples

我的问题是我想将打印重定向到csv文件,我尝试使用csv.writer进行整理,但出现错误。

我要获取一个csv文件

我尝试过:

rows = [
    ["La moyenne de frameRate est :",statistics.mean(numberList),"FPS"]
    ["Le frame rate max est:",max(numberList),"FPS"]
    ["Le FrameRate minimum est:",min(numberList),"FPS"]
    ["L'ecart type des FrameRate est:",statistics.stdev(numberList),"FPS"]
]
with open("C:\\Users\\skehal\\Desktop\\doc.csv",'wt') as csvfile:
    csv_writer = csv.writer(csvfile)
    for row in rows:
        csv_writer.writerow(row)

print("La moyenne de FrameRate est :" , statistics.mean(numberList),"FPS")
max(numberList)
print("Le frame rate max est:",max(numberList),"FPS")
min(numberList)
print("Le FrameRate minimum est:",min(numberList),"FPS")
print("L'ecart type des FrameRate est:",statistics.stdev(numberList),"FPS")

rows = [
    ["La moyenne de frameRate est :",statistics.mean(numberList),"FPS"]
    ["Le frame rate max est:",max(numberList),"FPS"]
    ["Le FrameRate minimum est:",min(numberList),"FPS"]
    ["L'ecart type des FrameRate est:",statistics.stdev(numberList),"FPS"]
]
with open("C:\\Users\\skehal\\Desktop\\doc.csv",'wt') as csvfile:
    csv_writer = csv.writer(csvfile)
    for row in rows:
        csv_writer.writerow(row)

我在控制台上收到此错误:

["Le frame rate max est:",max(numberList),"FPS"]
TypeError: list indices must be integers or slices, not tuple

0 个答案:

没有答案