pexpect and unicode strings

Mathew Oakes mathew.oakes at memechine.org
Fri Sep 4 22:11:43 EDT 2009


Is there anything that can be done to make pexpect spawns send unicode lines?

In this example they are just middot characters, but this process
needs to be able to handle languages in other character sets.

>>> spokentext = u'Nation . Search the FOX  Nation . czars  \xb7  Health care  \xb7  town halls  \xb7  tea parties  ...'
>>> p = pexpect.spawn('festival')
>>> p.expect('festival> ')
0
>>> p.sendline( spokentext )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/dist-packages/pexpect.py", line 961, in sendline
    n = self.send(s)
  File "/usr/lib/python2.6/dist-packages/pexpect.py", line 953, in send
    c = os.write(self.child_fd, s)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb7' in
position 41: ordinal not in range(128)
>>>

Help appreciated!

cheeers
Mat



More information about the Python-list mailing list