Re: \x and strings



"Martin Richter [MVP]" <martin.richter@xxxxxxxx> wrote in message
news:d3ljbm$o2i$1@xxxxxxxxxxxx
> Hallo John Carson!
>
>> "Martin Richter [MVP]" <martin.richter@xxxxxxxx> wrote in message
>> news:d3laie$d1s$1@xxxxxxxxx
>>
>>>
>>> If it is a non-unicode string
>>> a\x01bc
>>> will do it.
>>>
>>> If it is a unicode string use
>>> a\x001bc
>>
>>
>>
>> Have you tried compiling this? (It doesn't compile for me.)
>
> No. I am sorry about the wrong infos.
>
> I just read the docs. And I thought that the parser stopped after 2 or 3
> chars, becuase the docuemntation should explicitly 2 and 3 chars after \x.
> In fact it parses all chars unti it find a character not matching the
> sequence and this causes an overflow.
> So the only way is what John Carson wrote.
>


The escape sequence for embedded bytes is three characters following the \x
so your "unicode" example is the correct way for non-unicode strings,
a\x001bc will work properly for single byte characters.

--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.


.



Relevant Pages

  • Re: From python to LaTeX in emacs on windows
    ... > In the file there is international characters like é and ó. ... > I read the file into python as a string and suddenly the characters ... > Second problem: ... convert the unicode string back to a byte sequence. ...
    (comp.lang.python)
  • Re: string.replace non-ascii characters
    ... characters of ordinal value> 127. ... why I had a unicode string though. ... I thought urllib2 always spat out ...
    (comp.lang.python)
  • Re: How to find number of characters in a unicode string?
    ... and not in bytes to represent the characters. ... Decode the byte string and use `len` on the unicode string. ... these 4 symbols are all considered *single* letter symbols:) If your ...
    (comp.lang.python)
  • Re: problems with  character
    ... had encoded a unicode string into utf-8. ... I have a mysql database with characters like   » in it. ... trying to write a python script to remove these, ...
    (comp.lang.python)