Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string': 0.09; 'encode': 0.09; 'formatting': 0.09; 'strings.': 0.09; 'subject:characters': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'line),': 0.16; 'subject:Formatting': 0.16; 'way;': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'print': 0.22; 'string,': 0.24; 'unicode': 0.24; 'mon,': 0.24; '(or': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '3.x': 0.31; 'becomes': 0.33; 'entirely': 0.33; 'guess': 0.33; 'subject:with': 0.35; "can't": 0.35; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'anything': 0.39; 'entire': 0.61; 'first': 0.61; 'kind': 0.63; '2015': 0.84; '3.4': 0.84; 'end.': 0.84; 'subject:printing': 0.84; 'to:none': 0.92 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:cc :content-type; bh=sOU78cJ120VLPoi5hj3CBJ6AAjyAyCADmgGkdvEu/zw=; b=06gq291X1L1kjpZguDbxCWQOxtn4PQ5ih58JdiMnTsoXoHsLI+CoNsqx0WVizUvz6P cxv+1uhDbYvn3FXpUCcPKxtbgsgHi80mhuiMLNX/pUm9pwZayBO7/z3TOI/BRbR7NEKy ZLSo4PryPqihMXaLl6WuRWWjuIH0V+kA5nKDr/ZKPfm5rfQwDHPH9mtMxRgoQjC9rSdj N2sPg7p2h9YZt7hIgfwYG1nqQc1iClIo74isUCUxDn0lHzUN8hhm9Rh4TmGIikZ15Ryd lGnIFD8atYUkAEaMEPQfhZkNDAsYhZIsiXClSQd4MAa5wEQKKL4rGJ/U8zBEKYDeMEd5 Lc6A== MIME-Version: 1.0 X-Received: by 10.50.66.179 with SMTP id g19mr13829812igt.34.1421604834586; Sun, 18 Jan 2015 10:13:54 -0800 (PST) In-Reply-To: References: Date: Mon, 19 Jan 2015 05:13:54 +1100 Subject: Re: Formatting string with accented characters for printing From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421604837 news.xs4all.nl 2852 [2001:888:2000:d::a6]:39389 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83994 On Mon, Jan 19, 2015 at 3:04 AM, Jerry Rocteur wrote: > > I've tried both: > > print '{0:2} {1:25} {2} '.format( cnt, nam[num].encode('utf-8'), > steps[ind1]) > print "%3d %-25s %-7s" % ( cnt, nam[num].encode('utf-8'), steps[ind1]) > > I've searched but I can't see a solution.. > > I guess it is the way I'm printing nam[num].encode('utf-8') perhaps I > have to convert it first ? Do the formatting on a Unicode string, and then encode the entire string at the end. Or, better still, just work entirely with Unicode all the way; if you switch to Python 3.4 (or anything else in the 3.x line), print() takes Unicode strings. This kind of thing becomes easy. ChrisA