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:
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:
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?