我正在获取一个文件,以便在第一次读取后重置。所有的谷歌搜索都没有任何帮助。
如何在第一次读取文件后将其重置为begin?
试验一:
inFile = QFile( self._pathFileName )
inFile.open(QFile.ReadOnly | QFile.Text)
stream = QTextStream(inFile)
# Count first all lines in the file
self._numLinesRead = 0
self._mumLinesTotal = 0
while not stream.atEnd():
self._mumLinesTotal=+1
stream.readLine();
inFile.seek(0)
stream.seek(0)
pos = stream.pos() # pos is equal to 0 after this line verified with debugging
while( not stream.atEnd() ): # but here it still thinks he's at file end and jumps over
....试验二:
inFile = QFile( self._pathFileName )
inFile.open(QFile.ReadOnly | QFile.Text)
stream = QTextStream(inFile)
# Count first all lines in the file
self._numLinesRead = 0
self._mumLinesTotal = 0
while not stream.atEnd():
self._mumLinesTotal=+1
stream.readLine();
inFile.close()
del inFile
del stream
inFile = QFile( self._pathFileName )
inFile.open(QFile.ReadOnly | QFile.Text)
stream = QTextStream(inFile)
# everyting has been reset?!
while( not stream.atEnd() ): # Nop it still thinks it is atEnd and jumps over
....我尝试了在网上找到的所有解决方案。什么都没有用。我哪里做错了?
发布于 2021-08-26 05:23:01
不知道我应该说什么,但在系统完全重启后,“试用二”起作用了。
在第二次重启之后(两天后进行了大量代码更改),“试用版一”也恢复了活力。
毕竟:从我的角度来看,这两个试验都是有效和有效的。
如果您在开发和调试过程中发现奇怪的行为,请尝试重新启动。
https://stackoverflow.com/questions/68910589
复制相似问题