Solve python error "cannot use a string pattern on a bytes-like object"

I encountered the following error when compiling the ios library of opencv today

cannot use a string pattern on a bytes-like object

The reason is that the input of the re.match method is a string in b' ' format, which cannot be directly parsed

ret = check_output(["xcodebuild", "-version"])
print("ret:", ret)
m = re.match(r'Xcode\s+(\d+)\..*', ret, flags=re.IGNORECASE)

The solution is very simple, just parse the string manually.

for example:

ret = check_output(["xcodebuild", "-version"]).decode('utf-8')

Isn't it super simple?

Guess you like

Origin blog.csdn.net/qq_19313495/article/details/127285556