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=''不是正常的嘛。

阅读 2.4k
2 个回答

image.png

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

新手上路,请多包涵

我这边使用 mydir模块 使用json 模块 和 os 模块 测试通过 没有错误。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题