With python 3.8 I am trying to get a list of git
logs using subprocess
, and then to process them. Here is a piece of the code:
lines = subprocess.check_output(
[
"git",
"log",
"--all",
"--no-merges",
"--shortstat",
"--reverse",
"--pretty=format:'%ad;%an'",
]
).splitlines()
for line in lines:
print(line)
if "file changed" in line or "files changed" in line:
print("do something")
But I get an error:
....
if "file changed" in line or "files changed" in line:
TypeError: a bytes-like object is required, not 'str'
and the line print gives some output like
b"'Tue Nov 9 10:18:31 2010 +0000;someuser'"
That object looks like a byte object (see the 'b'?). Converting that object to a str
and printing it, I get:
print(str(line))
b"'Tue Nov 9 10:18:31 2010 +0000;someuser'"
But I do not want to work with byte objects, I want to work with simple strings! So I am not sure what is going on. And why there are two quotes in that line.
How to convert the lines I get from the splitlines
to normal strings I can compare with in if
statements ad given in the code example?