小编oli*_*tit的帖子

Python 2.7混合迭代和读取方法会丢失数据

我有一些问题可以在Python 3中运行,但在2.7中失败.我有以下部分代码:


def getDimensions(file,log):
noStations = 0 
noSpanPts = 0 
dataSet = False

if log:
    print("attempting to retrieve dimensions. Opening file",file)

while not dataSet:      
    try: # read until error occurs
        string = file.readline().rstrip() # to avoid breaking on an empty line
    except IOError:
        break
Run Code Online (Sandbox Code Playgroud)

    if "Ax dist hub" in string: # parse out number of stations
        if log:
            print("found ax dist hub location") 
        next(file) # skip empty line
        eos = False # end of stations
        while not eos:
            string …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

3
推荐指数
1
解决办法
9065
查看次数

标签 统计

python ×1

python-2.7 ×1