Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Only a fool fights in a burning house. -- Kank the Klingon, "Day of the Dove", stardate unknown


devel / comp.lang.python / Re: Printing Unicode strings in a list

SubjectAuthor
o Re: Printing Unicode strings in a listCameron Simpson

1
Re: Printing Unicode strings in a list

<mailman.270.1651151241.20749.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18072&group=comp.lang.python#18072

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: cs...@cskk.id.au (Cameron Simpson)
Newsgroups: comp.lang.python
Subject: Re: Printing Unicode strings in a list
Date: Thu, 28 Apr 2022 21:58:21 +1000
Lines: 61
Message-ID: <mailman.270.1651151241.20749.python-list@python.org>
References: <CAP=-cKXWHH8f+479sn5c=KzYV=_gEu+9UZ+kFk5at-KiDFjQJA@mail.gmail.com>
<YmqBXWrlMzQ6s9z6@cskk.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de Wyv2y9P3Xp95bTXPeDoUawLT24v8MiQvrhG+XwdU9+SQ==
Return-Path: <cameron@cskk.id.au>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'looks': 0.02; 'string':
0.07; 'that?': 0.07; 'log:': 0.09; 'prints': 0.09;
'subject:Unicode': 0.09; 'cheers,': 0.11; 'subject:list': 0.11;
'log': 0.12; 'import': 0.15; '(instead': 0.16; '3.x': 0.16;
'>>>>': 0.16; '__future__': 0.16; 'anyway.': 0.16; 'behaviour':
0.16; 'cameron': 0.16; 'displayed': 0.16; 'from:addr:cs': 0.16;
'from:addr:cskk.id.au': 0.16; 'from:name:cameron simpson': 0.16;
'message-id:@cskk.homeip.net': 0.16; 'pythonic': 0.16;
'received:10.10': 0.16; 'respect?': 0.16; 'simpson': 0.16; 'skip:>
10': 0.16; 'unicode': 0.16; 'wrote:': 0.16; 'python': 0.16;
'to:addr:python-list': 0.20; 'run': 0.23; 'normally': 0.26; 'bit':
0.27; 'function': 0.27; 'output': 0.28; 'header:User-Agent:1':
0.30; 'course.': 0.32; 'empty': 0.32; 'to:name:python': 0.32;
'but': 0.32; 'there': 0.33; 'same': 0.34; 'printing': 0.34;
'header:In-Reply-To:1': 0.34; 'item': 0.35; 'yes,': 0.35;
'following': 0.35; 'those': 0.36; 'using': 0.37; 'way': 0.38;
'could': 0.38; 'list': 0.39; 'still': 0.40; 'want': 0.40;
'should': 0.40; 'to:': 0.62; 'love': 0.62; 'leading': 0.63;
'hear': 0.64; 'your': 0.64; 'top': 0.65; 'produce': 0.65;
'received:userid': 0.66; 'arising': 0.67; 'header:Received:6':
0.67; '2015,': 0.69; 'you.': 0.71; 'reasons': 0.84; 'exhibit':
0.84; 'invalid.': 0.84; 'pint': 0.84; 'strings': 0.84
X-RG-Spam: Unknown
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvfedrudejgdeghecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfupfevtfgpvffgnffuvffttedpqfgfvfenuceurghilhhouhhtmecugedttdenucenucfjughrpeffhffvuffkgggtugfgjggffhesthekredttderjeenucfhrhhomhepvegrmhgvrhhonhcuufhimhhpshhonhcuoegtshestghskhhkrdhiugdrrghuqeenucggtffrrghtthgvrhhnpeektdejheekfedtveevieetkeefledukefgveeltdffteeugefgtddtgeevgedvjeenucfkphepuddrudeggedrvdeffedrvdegkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhephhgvlhhopegsohhrghdrtghskhhkrdhhohhmvghiphdrnhgvthdpihhnvghtpedurddugeegrddvfeefrddvgeekpdhmrghilhhfrhhomheptggrmhgvrhhonhestghskhhkrdhiugdrrghupdhnsggprhgtphhtthhopedupdhrtghpthhtohepphihthhhohhnqdhlihhsthesphihthhhohhnrdhorhhg
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-RG-VS-CLASS: clean
X-Authentication-Info: Submitted using ID cskk@bigpond.com
Mail-Followup-To: Python <python-list@python.org>
Content-Disposition: inline
In-Reply-To: <CAP=-cKXWHH8f+479sn5c=KzYV=_gEu+9UZ+kFk5at-KiDFjQJA@mail.gmail.com>
User-Agent: Mutt/2.2.1 (2022-02-19)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <YmqBXWrlMzQ6s9z6@cskk.homeip.net>
X-Mailman-Original-References: <CAP=-cKXWHH8f+479sn5c=KzYV=_gEu+9UZ+kFk5at-KiDFjQJA@mail.gmail.com>
 by: Cameron Simpson - Thu, 28 Apr 2022 11:58 UTC

On 28Apr2022 12:32, Stephen Tucker <stephen_tucker@sil.org> wrote:
>Consider the following log from a run of IDLE:
>==================
>
>Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)]
>on win32
>Type "copyright", "credits" or "license()" for more information.
>>>> print (u"\u2551")
>║
>>>> print ([u"\u2551"])
>[u'\u2551']
>>>>
>==================
>
>Yes, I am still using Python 2.x - I have good reasons for doing so and
>will be moving to Python 3.x in due course.

Love to hear those reasons. Not suggesting that they are invalid.

>I have the following questions arising from the log:
>1. Why does the second print statement not produce [ ║] or ["║"] ?

Because print() prints the str() or each of its arguments, and str() of
a list if the same as its repr(), which is a list of the repr()s of
every item in the list. Repr of a Unicode string looks like what you
have in Python 2.

>2. Should the second print statement produce [ ║] or ["║"] ?

Well, to me its behaviour is correct. Do you _want_ to get your Unicode
glyph? in quotes? That is up to you. But consider: what would be sane
output if the list contained the string "], [3," ?

>3. Given that I want to print a list of Unicode strings so that their
>characters are displayed (instead of their Unicode codepoint definitions),
>is there a more Pythonic way of doing it than concatenating them into a
>single string and printing that?

You could print them with empty separators:

print(s1, s2, ......, sep='')

To do that in Python 2 you need to:

from __future__ import print_function

at the top of your Python file. Then you've have a Python 3 string print
function. In Python 2, pint is normally a statement and you don't need
the brackets:

print u"\u2551"

but print() is genuinely better as a function anyway.

>4. Does Python 3.x exhibit the same behaviour as Python 2.x in this respect?

Broadly yes, except that all strings are Unicode strings and we don't
bothing with the leading "u" prefix.

Cheers,
Cameron Simpson <cs@cskk.id.au>


devel / comp.lang.python / Re: Printing Unicode strings in a list

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor