代码如下:
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)
在命令行中运行时报语法错误:
我试了好几遍,也和书上仔细对过,然后查过print的语法规则还是没看出print('%02d) %s' % (count, attr), end=" ")
这一句到底问题出在哪了,求指教
去掉后面的end=' '倒是可以正常运行,但是end=''不是正常的嘛。
什么版本python?我这python3.6.7可以