回路是否有pythonic的方法(我,我可以使用范围循环知道(LEN(..)),并得到一个指数)做下面的例子:在蟒蛇
for line in list_of_strings:
if line[0] == '$':
while line[-1] == '#':
# read in the Next line and do stuff
# after quitting out of the while loop, the next iteration of the for loop
# should not get any of the lines that the while loop already dealt with
本质,嵌套的同时,循环应该增加for循环。
编辑:没有一个文件句柄,混淆了两件事我工作的,它的串
列表
使用line.startswith和line.endswith而不是line [0]和line [-1]。它适用于空行。而且看起来更好:)。 – utdemir
@utdemir:心灵吹,我已经做了'LEN(线)这么多的检查> 0' – pseudosudo