小编Mig*_*ano的帖子

一行如果else语句拒绝工作

很抱歉提交这么小的问题,但它让我疯了.我有这一行永久给我语法错误:

print(BDF) if header is 1
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

print(BDF) if (header == 1)
Run Code Online (Sandbox Code Playgroud)

这是完整的功能:

def CSVtoDict(BDF, prune, header):
    # Comes with the option to prune [] and to use headers
    with open('%s%s.csv' % (dataDir,BDF), mode='r') as infile:
        reader = csv.reader(infile)
        saved = {}
        for row in reader:
            key = row[0]
            saved[key] = [r for r in row[1:] if not (r is '' and prune is 1)]
        print(BDF) if header is 1
    return saved
Run Code Online (Sandbox Code Playgroud)

什么可能导致这个?我正在调用函数:

adsMut = CSVtoDict(BaseDataFiles[0],1,1)
Run Code Online (Sandbox Code Playgroud)

一切似乎都井井有条,每次都只给我语法错误.

python syntax if-statement syntax-error python-3.x

0
推荐指数
2
解决办法
104
查看次数

标签 统计

if-statement ×1

python ×1

python-3.x ×1

syntax ×1

syntax-error ×1