Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

print语法报错

代码如下:

seplen = 60
sepchr = '-'

def listing(module, verbose=True):
    sepline = sepchr * seplen
    if verbose:
        print(sepline)
        print('name:', module.__name__, 'file:', module.__file__)
        print(sepline)

    count = 0
    for attr in module.__dict__:
        # print('%02d) %s' % (count, attr), end = ' ')
        print('%02d) %s' % (count, attr), end=" ")
        if attr.startswith('__'):
            print('<built-in name>')
        else:
            print(getattr(module, attr))
        count += 1

    if verbose:
        print(sepline)
        print(module.__name__, 'has %d names' % count)
        print(sepline)

if __name__ == '__main__':
    import mydir
    listing(mydir)

在命令行中运行时报语法错误:
批注 2020-06-09 224957.png
我试了好几遍,也和书上仔细对过,然后查过print的语法规则还是没看出
print('%02d) %s' % (count, attr), end=" ")
这一句到底问题出在哪了,求指教
去掉后面的end=' '倒是可以正常运行,但是end=''不是正常的嘛。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

image.png

什么版本python?我这python3.6.7可以


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...