這讓我頭痛不已。我的代碼:如何從Python3中的變量/文本文件中刪除b和 n? (TypeError)
import subprocess
proc = subprocess.Popen("php /var/scripts/data.php", shell=True, stdout=subprocess.PIPE)
scriptresponse = proc.stdout.read()
print (scriptresponse)
輸出:
b'January\n'
我試圖scriptresponse.replace ('\n', '')
但失敗:
TypeError: 'str' does not support the buffer interface
如何從scriptresponse
刪除b
和\n
因此輸出看起來就像這樣:
January