0

基本上,我想用学校科目和我从中得到的所有测试结果制作一个网格,我想为每个科目显示大约 10 个结果。

像这样:

...
--------------------------------------------------------------------
English| 7.4 | 6.4 | 9.5 | 4.5 | 8.9 | 3.9 | 8.0 | 6.5 | 9.9 | 4.9 |
--------------------------------------------------------------------
Dutch  | Results
...

我基本上做了两个 FOR 循环,一个从列表中读取每个学校科目,一个从列表中读取每个结果。但是,我希望它们完成而不会在下一个循环中“卡住”。我该怎么做呢?我是否将两个循环穿线并进行时间延迟,以便每 x 秒读取一次值?(可能不是这个,这个很慢)

代码:

...
for item in store: #Loop that reads the subjects
        with open("matrixcontent.dat", "r") as matrixcontent_open:
            lines = matrixcontent_open.readlines() #Lines are test results
        for line in lines:
            print(item + "|" + line + "\n" + ("-------------" * 7))
            #I want this last line to print the subject and than all the results

编辑:

使用下面的解决方案(有点),它将打印所有测试结果,但它会打印错误。如何将所有测试结果打印在一个单独的列/行中?我希望所有这些数字都在 NTL(荷兰语)行中。

新台币 | 7.2


ETL | 8.4


西伯利亚 | 6.7


WID | 5.3


信息通信技术 | 4.8


网络存储 | 9.4


SCK | 10.0

4

1 回答 1

1

If I understand correctly, your matrixcontent.dat contains all the scores for each subject, one set per line, and the order of the lines correspond to the order of the subjects in your store list variable.

In which case, you only need one loop, either over the lines in matrixcontent.dat or over the store variable.

Something like this ought to work...

with open("matrixcontent.dat", "r") as matrixcontent_open:
    for item in store:
        line = next(matrixcontent_open)
        print(item + "|" + line + "\n" + ("-------------" * 7))
于 2013-06-24T16:45:06.437 回答