import os
filePath = "C:\\Users\\siba\\Desktop\\1x1x1.blb"
BrickName = (os.path.splitext(os.path.basename(filePath))[0])
import sys
def ImportBLB(filePath):
file = open(filePath)
line = file.readline()
while line:
if(line == "POSITION:\n"):
POS1 = file.next()
POS2 = file.next()
POS3 = file.next()
POS4 = file.next()
sys.stdout.write(POS1)
sys.stdout.write(POS2)
sys.stdout.write(POS3)
sys.stdout.write(POS4)
return
line = file.readline()
file.close()
return
ImportBLB(filePath)
我试图在找到“位置:”行时一次读取文件四行,但由于返回语句结束循环,这仅输出前四行。
删除 return 语句会给我一个“ValueError:混合迭代和读取方法会丢失数据”错误,我将如何解决这个问题?