0
以下函數應該打印200行,而只打印「[]」。我不完全確定我在這裏出了什麼問題,並希望有一雙新的眼睛能夠幫助我。islice怎麼只打印[]?
謝謝!
def main():
from itertools import islice
userfile = raw_input("Please enter the file you wish to open\n(must be in this directory): ")
file1 = open(userfile, "r+")
jcardtop = file1.read(221);
#print jcardtop
n = 200
while True:
next_n_lines = list(islice(file1,n))
if not next_n_lines:
break
print next_n_lines
你肯定'file1'有更多的線,你已經閱讀了第一221個字節之後? – mgilson
@IanAuld:你真的不應該修改後修復縮進錯誤時,問題幾乎可以肯定是由壓痕引起... – abarnert