Python-Codierung für pipe.communicate

Ich rufe anpipe.communicate von Pythonssubprocess -Modul aus Python 2.6. Ich erhalte den folgenden Fehler von diesem Code:

from subprocess import Popen

pipe = Popen(cwd)

pipe.communicate( data )

Für ein beliebigescwd, und wodata das Unicode enthält (speziell 0xE9):

Exec. exception: 'ascii' codec can't encode character u'\xe9' in position 507: ordinal not in range(128)
Traceback (most recent call last):  

... stdout, stderr = pipe.communicate( data )

  File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py",
line 671, in communicate
    return self._communicate(input)

  File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py",
line 1177, in _communicate
    bytes_written = os.write(self.stdin.fileno(), chunk)

Das passiert, nehme ich an, weilpipe.communicate() erwartet eine ASCII-codierte Zeichenfolge, aberdata ist Unicode.

Ist dies das Problem, auf das ich stoße, und ich finde eine Möglichkeit, Unicode an @ zu übergebpipe.communicate()?

Danke fürs Lesen!

Brian

Antworten auf die Frage(2)

Ihre Antwort auf die Frage