问题描述
我怎么能跳过使用循环打印最后一行(for / while)
例如
for open(文件):
打印行。
我想跳过打印文件的最后一行。谢谢
how can i skip printing the last line using loops (for /while)
eg
for line in open("file):
print line.
I want to skip printing last line of the file.thanks
推荐答案
afile = open (文件名)
xlines = afile.xreadlines()
aline = xlines.next
for nextline in xlines:
打印aline
aline = nextline
James
afile = open(filename)
xlines = afile.xreadlines()
aline = xlines.next
for nextline in xlines:
print aline
aline = nextline
James
afile = open(文件名)
xlines = afile.xreadlines()
aline = xlines.next
$ x $ b for xline的nextline:
print aline
aline = nextline
James
afile = open(filename)
xlines = afile.xreadlines()
aline = xlines.next
for nextline in xlines:
print aline
aline = nextline
James
Shoule be
aline = xlines.next()
Shoule be
aline = xlines.next()
这篇关于跳过循环中的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!