【发布时间】:2013-06-24 16:36:18
【问题描述】:
基本上,我想用学校科目和我从中获得的所有测试结果制作一个网格,我想为每个科目显示大约 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(荷兰语)行中。
NTL | 7.2
ETL | 8.4
WIB | 6.7
WID | 5.3
信息通信技术 | 4.8
NAS | 9.4
SCK | 10.0
【问题讨论】:
-
“卡住”是什么意思?
-
@kindall 它将在存储循环中开始,然后在行循环中继续并留在那里直到完成。我希望它一个接一个地完成,但不是在第一个完成之后。
-
所以
matrixcontent.dat有您所有商品的数据吗?结尾有新内容吗? -
@cmd matrixcontent.dat 包含了所有的测试结果,没有添加新的内容。
标签: python multithreading for-loop grid multitasking