问题遇到的现象和发生背景
python 3.9
TypeError: can't concat str to bytes
用代码块功能插入代码,请勿粘贴截图
def PromoteUnstagedFiles(fileList):
if not fileList:
return
unstaged = RunProc("git", "diff-files", "--name-status", *fileList)
if unstaged:
sys.stdout.write("you have unstaged files, stage/discard them first.\n")
sys.stdout.write(unstaged + "\n")
sys.exit(1)
运行结果及报错内容
sys.stdout.write(unstaged + "\n")
TypeError: can't concat str to bytes
我的解答思路和尝试过的方法
sys.stdout.write(unstaged.decode("utf-8") + b"\n")
sys.stdout.write(unstaged.decode("utf-8") + b"\n")
TypeError: can only concatenate str (not "bytes") to str