Python双FOR循环无线程 [英] Python double FOR loops without threading
问题描述
像这样:
...
--------------- -------------------------------------------------- ---
English | 7.4 | 6.4 | 9.5 | 4.5 | 8.9 | 3.9 | 8.0 | 6.5 | 9.9 | 4.9 |
---------------------------------------------- ----------------------
荷兰语|结果
...
我做了两个FOR循环,不在列表中,而是从列表中读取每个结果。
但是,我希望他们完成,而不会在下一个循环卡住。
我该怎么做?线程两个循环,并做一个时间延迟,这样的值是每X秒可读? (可能不是这个,这很慢)
$ $ $ $ $ $ $ $ > ...
在商店中的商品:#Loop读取作为matrixcontent_open:
lines = matrixcontent_open.readlines() #行是测试结果
行:
print(item +|+ line +\\\
+(------------- * 7))
#我想要这最后一行打印主题,并比所有结果
编辑:
在解决方案(稍微)下面,它会打印所有的测试结果,但它会打印错误。我如何管理打印所有的测试结果在一个单独的列/行?我希望所有这些号码都在NTL(荷兰语)行。
NTL | 7.2
ETL | 8.4
WIB | 6.7
WID | 5.3
ICT | 4.8
NAS | 9.4
SCK | 10.0
如果我理解正确,您的 matrixcontent.dat
每个主题的分数,每行一个集合和行的顺序对应于存储
列表变量中的主题顺序。
在这种情况下,只需要一个循环,或者在 matrixcontent.dat
或者在 store
变量。
类似这样的东西应该可以工作。打开(matrixcontent.dat,r)作为matrixcontent_open:
在商店中的项目:
line = next(matrixcontent_open)
print(item + |+ line +\\\
+(-------------* 7))
Basically, I want to make a grid with school subjects and all the test results I got from it, and I want to display about 10 results for every subject.
Like this:
...
--------------------------------------------------------------------
English| 7.4 | 6.4 | 9.5 | 4.5 | 8.9 | 3.9 | 8.0 | 6.5 | 9.9 | 4.9 |
--------------------------------------------------------------------
Dutch | Results
...
And I made basically two FOR loops, one reading every school subject out of a list and one that reads every result out of a list. However, I want them to complete without going "stuck" in the next loop. How do I do this? Do I thread the two loops and make a time delay so the values are readable every x seconds? (Probably not this, this is very slow)
Code:
...
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
EDIT:
With the solution (somewhat) down below, it will print all the test results, but It will print it wrong. How do I manage to print all the test results in one individual column/row? I would like all these number to be in the NTL (Dutch) row.
NTL | 7.2
ETL | 8.4
WIB | 6.7
WID | 5.3
ICT | 4.8
NAS | 9.4
SCK | 10.0
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))
这篇关于Python双FOR循环无线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!