1

I am trying to extract a line from neofetch with regex , which works but it also outputs some garbled mess:

['OS:\x1b[0m Raspbian 10 buster\x1b[0m']

Now I was wondering if you could convert that to plain ASCII. I know it isn't possible directly, but maybe there is a library or something that leaves out the non-convertible things?

I tried:

output = output.read().decode('ascii')

As expected it returns:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 611: ordinal not in range(128)
Palomar
  • 51
  • 7
  • The answers to this question may help you: https://stackoverflow.com/questions/8689795/how-can-i-remove-non-ascii-characters-but-leave-periods-and-spaces-using-python – Altareos Apr 17 '21 at 22:26
  • You can simply use `neofetch --stdout` to turn off colours etc. (The unicode characters that you see are due to those colours). Also, you can fetch that system information in other more pythonic ways, unless you absolutely must use `neofetch` – Hrishikesh Apr 17 '21 at 22:46
  • Thanks, I didnt know that.Neofetch --stdout worked great ty :D – Palomar Apr 17 '21 at 22:58
  • FYI every character in your "garbled mess" *is* ASCII, but the `0xc2` in your error message is not. – Mark Tolonen Apr 19 '21 at 00:34

0 Answers0