如何使用csv从保存到文本文件转换为保存到python中的excel文件

时间:2016-04-10 09:23:07

标签: python excel csv random

我一直在编写数学测验,并且一直在保存我对文本文件的答案,但是现在我想将这些保存到excel文件中,并且我被告知我需要导入cvs并使用它。我试着这样做,但后来我收到了大量的错误。任何答案都会非常感激。我觉得我现在的代码很容易理解并且用户友好。

class_number = prompt_int_big("Before your score is saved ,are you in class 1, 2 or 3? Press the matching number")

filename = (str(class_number) + "csv")
with open(filename, 'a') as f:
    f.write("\n" + str(name) + " scored " + str(score) +  " on difficulty level " + str(level_of_difficulty) + "\n")
with open(filename) as f:
    lines = [line for line in f if line.strip()]
    lines.sort()

if prompt_bool("Do you wish to view previous results for your class"):
    for line in lines:
        print (line)
else:
    sys.exit("Thanks for taking part in the quiz, your teacher should discuss your score with you later")

0 个答案:

没有答案