0
這個子過程代碼在Python 2中完美工作,但在Python 3中完美工作。我該怎麼辦?子過程在Python 2中工作,但不在Python 3中
感謝,
import subprocess
gnuchess = subprocess.Popen('gnuchess', stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
# Python 3 strings are Unicode and must be encoded before writing to a pipe (and decoded after reading)
gnuchess.stdin.write('e4\n'.encode())
while True:
L = gnuchess.stdout.readline().decode()
L = L[0:-1]
print(L)
if L.startswith('My move is'):
movimiento = L.split()[-1]
break
print(movimiento)
gnuchess.stdin.write('exit\n'.encode())
gnuchess.terminate()
當它不起作用時會發生什麼?你有例外嗎?如果是這樣,請包含回溯。如果你有其他行爲,請描述它。 – Blckknght