学习基础写打开文件程序,妈妈呀这么基础的我到底错哪了呀,为啥会out of range呢
def end(self):#半段段尾
print("end:")
while self.document.characters[self.position]!='\n' and self.position<len(self.document.characters) :
self.forward()
self.document.check()
print("end over")
结果发现原因是先满足self.position<len(self.document.characters)后self.document.characters[self.position]!='\n'
所以是
while self.position<len(self.document.characters) and self.document.characters[self.position]!='\n':
总结:个人基础太薄弱,后悔伤心脸。