Apr-26-2021, 12:40 AM
I'm currently trying to print the uname() results from the os module in a nice, readable manner.
Printing the uname() results directly like so isn't very readable:
sysname: (sysname's value)
nodename: (nodename's value)
release: (release's value)
version: (version's value)
machine: (machine's value)
But so far the only way I can get output like that is by doing this:
So I'd really like to know if there's some way to get both the field names and their values and print both out via a loop.
Sorry if my post is a bit crummy.
Printing the uname() results directly like so isn't very readable:
from os import uname os_info = uname() print(os_info) # Output # posix.uname_result(sysname='Linux', (nodename withheld), release='5.4.0-72-generic', # version='#80-Ubuntu SMP Mon Apr 12 17:35:00 UTC 2021', machine='x86_64')I'd like to get the output to look something like this:
sysname: (sysname's value)
nodename: (nodename's value)
release: (release's value)
version: (version's value)
machine: (machine's value)
But so far the only way I can get output like that is by doing this:
from os import uname os_info = f""" sysname: {uname().sysname} \n nodename: {uname().nodename} \n release: {uname().release} \n version: {uname().version} \n machine: {uname().machine} """Which is clunky. I know that uname() returns an object you can iterate over (__iter__ is listed as an available method). But if I try looping through os_info and printing the result, I only get the values, the field names themselves (sysname, nodename, etc.) aren't available.
So I'd really like to know if there's some way to get both the field names and their values and print both out via a loop.
Sorry if my post is a bit crummy.
