3

I'm using the sh Python library: https://amoffat.github.io/sh/ I'm trying to get name and e-mail address of the last commiter. I tried it like this:

from sh import git
name = str(git('show', format='%cN', s=True))

While on some machines this is perfectly safe, on some other ones the name variable will contain also some strange characters:

'\x1b[?1h\x1b=\rHonza Javorek\x1b[m\r\n\r\x1b[K\x1b[?1l\x1b>'

I believe they're some coloring escape characters, but the output actually isn't colored at all and even if I add --no-color to the command, the output stays the same.

How can I get rid of these characters? I tried to turn off colors in various ways and also some algorithms for removing the characters (e.g. those in Filtering out ANSI escape sequences or How to strip color codes used by mIRC users? or How can I remove the ANSI escape sequences from a string in python), but nothing really worked well with my string.

Community
  • 1
  • 1
Honza Javorek
  • 8,566
  • 8
  • 47
  • 66

0 Answers0