7bit to 8bit
Daniel Roth
d00roth at dtek.chalmers.se
Thu Apr 15 08:31:05 EDT 2004
Mark Rowe wrote:
>
> On 15/04/2004, at 15:05, Daniel Roth wrote:
>
>> how do one easy convert a 8bit-text, which by python seems to be in
>> 7bit, to 8bit? I want to convert '=F6' to 'ö', '=E4' to 'ä' and so on.
>> of course without doing a replace for all those characters.
>
>
> Strings containing sequences like '=F6' appear to have be latin-1
> strings that have been encoding using the "quoted printable" encoding.
> The following snippet shows one method of decoding the data:
>
> >>> print "=F6=E4".decode('quopri').decode('latin-1')
> öä
>
When I try your 'line' I get:
# python
Python 2.3.3 (#2, Apr 15 2004, 04:41:13)
[GCC 3.3.3 20040110 (prerelease) (Debian)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "=F6=E4".decode('quopri').decode('latin-1')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode characters in position
0-1: ordinal not in range(128)
>>>
> Alternatively, you should look into the quopri module and it's
> decodestring function.
>
Same here
> Hope this helps,
>
> Mark Rowe
> http://bdash.bluewire.net.nz
>
>
Thanks for the help
Daniel
More information about the Python-list
mailing list