Re: [Tutor] String encoding

2011-08-26 Thread Dave Angel
On 08/26/2011 11:49 AM, Prasad, Ramit wrote: Yep, it is. Thanks those charts are exactly what I wanted! Now I have another question. What is the difference between what print shows and what the interpreter shows? print s.decode('latin-1') MÉXICO The decoded characters are a Unicode string.

Re: [Tutor] String encoding

2011-08-26 Thread Steven D'Aprano
Prasad, Ramit wrote: Think about it this way... if I gave you a block of data as hex bytes: 240F91BC03...FF90120078CD45 and then asked you whether that was a bitmap image or a sound file or something else, how could you tell? It's just *bytes*, it could be anything. Yes, but if you give me da

Re: [Tutor] String encoding

2011-08-26 Thread Prasad, Ramit
>In this case, the encoding is almost certainly "latin-1". I know that >from playing around at the interactive interpreter, like this: > > >>> s = 'M\xc9XICO' > >>> print s.decode('latin-1') > MÉXICO > >If you want to see charts of various encodings, wikipedia has a bunch. > For instance, the Lati

Re: [Tutor] String encoding

2011-08-26 Thread Jerry Hill
On Thu, Aug 25, 2011 at 7:07 PM, Prasad, Ramit wrote: > Nice catch! Yeah, I am stuck on the encoding mechanism as well. I know how to > encode/decode...but not what encoding to use. Is there a reference that I can > look up to find what encoding that would correspond to? I know what the > chara

Re: [Tutor] String encoding

2011-08-26 Thread Prasad, Ramit
>Think about it this way... if I gave you a block of data as hex bytes: > >240F91BC03...FF90120078CD45 > >and then asked you whether that was a bitmap image or a sound file or >something else, how could you tell? It's just *bytes*, it could be anything. Yes, but if you give me data and then tell

Re: [Tutor] String encoding

2011-08-25 Thread Steven D'Aprano
Prasad, Ramit wrote: I don't know what they are from but they are both the same value, one in hex and one in octal. 0xC9 == 0311 As for the encoding mechanisms I'm afraid I can't help there! Nice catch! Yeah, I am stuck on the encoding mechanism as well. I know how to encode/decode...but not

Re: [Tutor] String encoding

2011-08-25 Thread Prasad, Ramit
>I don't know what they are from but they are both the same value, one in >hex and one in octal. > >0xC9 == 0311 > >As for the encoding mechanisms I'm afraid I can't help there! Nice catch! Yeah, I am stuck on the encoding mechanism as well. I know how to encode/decode...but not what encoding to

Re: [Tutor] String encoding

2011-08-25 Thread Alan Gauld
On 25/08/11 15:36, Prasad, Ramit wrote: I have a string question for Python2. Basically I have two strings with > non-ASCII characters and I would like to have a better understanding > of what the escapes are from ' M\xc9XICO' and ' M\311XICO' I don't know what they are from but they are bot

[Tutor] String encoding

2011-08-25 Thread Prasad, Ramit
I have a string question for Python2. Basically I have two strings with non-ASCII characters and I would like to have a better understanding of what the escapes are from and how to possibly remove/convert/encode the string to something else. If the description of my intended action is vague it i

Re: [Tutor] string encoding

2010-06-18 Thread Dave Angel
Rick Pasotto wrote: I can print the string fine. It's f.write(string_with_unicode) that fails with: UnicodeEncodeError: 'ascii' codec can't encode characters in position 31-32: ordinal not in range(128) Shouldn't I be able to f.write() *any* 8bit byte(s)? repr() gives: u"Realtors\\xc2\\xae"

Re: [Tutor] string encoding

2010-06-18 Thread Lie Ryan
On 06/18/10 14:21, Rick Pasotto wrote: >> Remember, even if your terminal display is restricted to ASCII, you can >> still use Beautiful Soup to parse, process, and write documents in UTF-8 >> and other encodings. You just can't print certain strings with print. > > I can print the string fine. It

Re: [Tutor] string encoding

2010-06-17 Thread Rick Pasotto
On Fri, Jun 18, 2010 at 12:24:25PM +1000, Lie Ryan wrote: > On 06/18/10 06:41, Rick Pasotto wrote: > > I'm using BeautifulSoup to process a webpage. One of the fields has a > > unicode character in it. (It's the 'registered trademark' symbol.) When > > I try to write this string to another file I g

Re: [Tutor] string encoding

2010-06-17 Thread Lie Ryan
On 06/18/10 06:41, Rick Pasotto wrote: > I'm using BeautifulSoup to process a webpage. One of the fields has a > unicode character in it. (It's the 'registered trademark' symbol.) When > I try to write this string to another file I get this error: > > UnicodeEncodeError: 'ascii' codec can't encode

[Tutor] string encoding

2010-06-17 Thread Rick Pasotto
I'm using BeautifulSoup to process a webpage. One of the fields has a unicode character in it. (It's the 'registered trademark' symbol.) When I try to write this string to another file I get this error: UnicodeEncodeError: 'ascii' codec can't encode characters in position 31-32: ordinal not in ra

Re: [Tutor] String Encoding problem

2009-04-20 Thread Strax-Haber, Matthew (LARC-D320)
0500 To: "Strax-Haber, Matthew (LARC-D320)" Cc: Python Tutor Subject: Re: [Tutor] String Encoding problem Can you give us a simple description of what you are trying to do? And if you can post in plain text instead of HTML that would be helpful. Maybe this will give you some ideas - you c

Re: [Tutor] String Encoding problem

2009-04-20 Thread Kent Johnson
Can you give us a simple description of what you are trying to do? And if you can post in plain text instead of HTML that would be helpful. Maybe this will give you some ideas - you can trap the control-D and do your cleanup: http://openbookproject.net/pybiblio/tips/wilson/simpleExceptions.php Ke

Re: [Tutor] String Encoding problem

2009-04-20 Thread Strax-Haber, Matthew (LARC-D320)
angley Research Center (LaRC) Co-op, Safety-Critical Avionics Systems Branch W: 757-864-7378; C: 561-704-0029 Mail Stop 130 matthew.strax-ha...@nasa.gov From: Martin Walsh Date: Mon, 20 Apr 2009 16:05:01 -0500 To: Python Tutor Cc: "Strax-Haber, Matthew (

Re: [Tutor] String Encoding problem

2009-04-20 Thread Martin Walsh
Forwarding to the list. Matt, perhaps you can repost in plain text, my mail client seems to have mangled your source ... Strax-Haber, Matthew (LARC-D320) wrote: >> *From: *Martin Walsh >> >> The environment available to __del__ methods during program termination >> is wonky, and apparently not ve

Re: [Tutor] String Encoding problem

2009-04-20 Thread Kent Johnson
On Mon, Apr 20, 2009 at 10:46 AM, Matt wrote: > Running this interactively, if you finish off with 'del db', it exits fine > and creates a skeleton xml file called 'db.xml' with text ''. > However, if you instead CTRL-D, it throws at exception while quitting and > then leaves an empty 'db.xml' whi

Re: [Tutor] String Encoding problem

2009-04-20 Thread Martin Walsh
Matt wrote: > Hey everyone, > > I'm hoping someone here can help me solve an odd problem (bug?). I'm > having trouble with string encoding, object deletion, and the xml.etree > library. If this isn't the right list to be posting this question, > please let me know. I'm new to Python and don't know

Re: [Tutor] String Encoding problem

2009-04-20 Thread Strax-Haber, Matthew (LARC-D320)
> From: spir > Date: Mon, 20 Apr 2009 12:22:59 -0500 > To: Python Tutor > Subject: Re: [Tutor] String Encoding problem > > Le Mon, 20 Apr 2009 10:46:47 -0400, > Matt s'exprima ainsi: > >> Hey everyone, >> >> I

Re: [Tutor] String Encoding problem

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 10:46:47 -0400, Matt s'exprima ainsi: > Hey everyone, > > I'm hoping someone here can help me solve an odd problem (bug?). I'm having > trouble with string encoding, object deletion, and the xml.etree library. If > this isn't the right list to be posting this question, please

[Tutor] String Encoding problem

2009-04-20 Thread Matt
Hey everyone, I'm hoping someone here can help me solve an odd problem (bug?). I'm having trouble with string encoding, object deletion, and the xml.etree library. If this isn't the right list to be posting this question, please let me know. I'm new to Python and don't know of any other "help me"