|
发表于 2021-4-6 18:07:29
|
显示全部楼层
如果你想格式化,我更喜欢使用格式包
- from tabulate import tabulate
-
- currentuser ={'root':{'uid': 0,'username': 'root' ,'shell': '/bin/bash'},
- 'daemon': {'uid': 1,'username': 'daemon' ,'shell': '/usr/sbin/nologin'},
- 'bin': {'uid': 2,'username': 'bin', 'shell':'/usr/sbin/nologin'},
- 'nsa': {'uid': 1000,'username': 'nsa', 'shell': '/bin/bash'}}
-
-
- columns = list(next(iter(currentuser.values())).keys())
- print(tabulate([x.values() for x in currentuser.values()], headers=columns, tablefmt="presto"))
复制代码 |
|