Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'encoding': 0.05; 'expected.': 0.09; 'python': 0.11; 'kurt': 0.12; 'easier.': 0.16; 'encoding.': 0.16; 'encodings': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'utf8': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'aug': 0.22; 'print': 0.22; 'string,': 0.24; 'unicode': 0.24; 'switch': 0.26; 'header :In-Reply-To:1': 0.27; 'function': 0.29; 'message- id:@mail.gmail.com': 0.30; '(which': 0.31; 'usually': 0.31; 'becomes': 0.33; 'actual': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'you.': 0.62; 'information': 0.63; 'different': 0.65; 'life': 0.66; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=bedpxpLj9mc0N7Bdx6+LBBWG59Zd3hYAyVjcOWhFz5I=; b=L6Y6svbtxgawsnWtFq6Rc/7Zt4RPjxmnccXdoLa/kJq3DKJLr5bN+5Aw2eKDSIpxNo HiUaQ3FgU7b30+RgmHhNMwBA4gvtvCvTFhOpLb4W5zsOW4ONJRY3lOwcnnxTUuL1UWn1 /GgGTaEf1aHhbD39bjkXzEruxJ7HGPw7xVQL3Z0QrV44AtZEBVavcUYspCM+E/ckVFvk xxtc4Rq/79Qiq6s1ML22BnLjMBVlUwrQuuCEsrBsPTf5whKJI7FjR8kCPi+oMZftWbHl rRRlA14bqBDOk5ZfgjTM+V0FCQna6eupB6zjrIuVPxTraRU5mpx081Cm7uUbbOLte5hS +hUA== MIME-Version: 1.0 X-Received: by 10.221.68.71 with SMTP id xx7mr4364998vcb.97.1375979856259; Thu, 08 Aug 2013 09:37:36 -0700 (PDT) In-Reply-To: <5203C468.4020001@gmail.com> References: <9781df99-f9c8-4217-aa67-7a714b7f2ebe@googlegroups.com> <5203B841.4060304@gmail.com> <5203C468.4020001@gmail.com> Date: Thu, 8 Aug 2013 17:37:36 +0100 Subject: Re: right adjusted strings containing umlauts From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375980242 news.xs4all.nl 15964 [2001:888:2000:d::a6]:36636 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52212 On Thu, Aug 8, 2013 at 5:16 PM, Kurt Mueller wrote: > Am 08.08.2013 17:44, schrieb Peter Otten: >> Kurt Mueller wrote: >>> What do I do, when input_strings/output_list has other codings like >>> iso-8859-1? >> >> You have to know the actual encoding. With that information it's easy: >>>>> output_list >> ['\xc3\xb6', '\xc3\xbc', 'i', 's', 'f'] >>>>> encoding = "utf-8" >>>>> output_list = [s.decode(encoding) for s in output_list] >>>>> print output_list >> [u'\xf6', u'\xfc', u'i', u's', u'f'] > > How do I get to know the actual encoding? > I read from stdin. There can be different encondings. > Usually utf8 but also iso-8859-1/latin9 are to be expected. > But sys.stdin.encoding sais always 'None'. If you can switch to Python 3, life becomes a LOT easier. The Python 3 input() function (which does the same job as raw_input() from Python 2) returns a Unicode string, meaning that it takes care of encodings for you. ChrisA