Python Forum
Is there a better way of formatting os.uname() output?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a better way of formatting os.uname() output?
#1
I'm currently trying to output the results from os.uname() to a Python window containing a QLabel.

The label requires the data as a string. I know various ways of converting the result into a string, but what I'd like to do is make the output look nice. Specifically:
  • Place each output field (sysname, release, etc.) onto a separate line.
  • Remove the commas.
  • Remove the opening and closing parentheses

Doing str(os.uname()) just gives one long line.

.replace() lets me insert newlines in place of the commas, but I'd have to use two additional .replace() calls to remove the opening and closing parentheses.

My best solution uses f-strings like so:

self.info = (f"{os.uname().sysname}\n\n"
             f"{os.uname().release}\n\n"
             f"{os.uname().version}\n\n"
              f"{os.uname().machine}"
              )

# Including this bit for context's sake.

self.text = QtWidgets.QLabel(self.info, alignment=QtCore.Qt.AlignCenter)
But that still seems rather clunky to me. Is there a better way of doing this, or should I just suck it up and use a loop?
Reply


Messages In This Thread
Is there a better way of formatting os.uname() output? - by CodeWolf - Aug-27-2021, 02:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Formatting float number output barryjo 2 956 May-04-2023, 02:04 PM
Last Post: barryjo
  Formatting to output file Mark17 2 1,358 Jan-13-2022, 09:06 PM
Last Post: BashBedlam
  Is there a better way to print uname information? EkaCaesium 4 3,808 Apr-26-2021, 12:51 PM
Last Post: EkaCaesium
  Output formatting Steffenwolt 0 2,195 Jan-18-2018, 03:47 PM
Last Post: Steffenwolt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020