Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > pexpect and unicode strings

Reply
Thread Tools

pexpect and unicode strings

 
 
Mathew Oakes
Guest
Posts: n/a
 
      09-05-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(12
>>>


Help appreciated!

cheeers
Mat
 
Reply With Quote
 
 
 
 
Sean DiZazzo
Guest
Posts: n/a
 
      09-05-2009
On Sep 4, 7:11*pm, Mathew Oakes <mathew.oa...@memechine.org> wrote:
> 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(12
>
>
>
> Help appreciated!
>
> cheeers
> Mat


Did you trying changing line 953 in the pexpect file to:

c = os.write(self.child_fd, s.encode("utf-8"))

and then run your code again?

Worth a shot. I have no good way of trying it out here.

~Sean
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the system clock with pexpect confuses pexpect! Saqib Ali Python 1 12-26-2011 01:51 PM
compare unicode to non-unicode strings Asterix Python 5 08-31-2008 07:31 PM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
pexpect and OpenVMS Adrian Casey Python 2 05-21-2004 03:14 PM
cygwin python with Tkinter and pexpect module =?ISO-8859-15?Q?J=F6rg?= Maier Python 2 09-07-2003 09:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57