May-03-2021, 07:50 AM
You can pass formatting with f-strings so little adjustment to menator01 code would deliver required result (numbers are aligned to right and text to left which is canonical way to display these datatypes in table style):
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'}} for value in currentuser.values(): print(f"{value['uid']:>8} {value['username']:<12} {value['shell']:<15}")This will print:
Output: 0 root /bin/bash
1 daemon /usr/sbin/nologin
2 bin /usr/sbin/nologin
1000 nsa /bin/bash
I personally like this type of display better than separated with |
. However, if you prefer that you can add these into f-string quite easily:for value in currentuser.values(): print(f"| {value['uid']:>8} | {value['username']:<12} | {value['shell']:<15}")This will deliver:
Output:| 0 | root | /bin/bash
| 1 | daemon | /usr/sbin/nologin
| 2 | bin | /usr/sbin/nologin
| 1000 | nsa | /bin/bash
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.