Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53134

Rép : Why is str(None) == 'None' and not an empty string?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <fp2161@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'plenty': 0.07; "subject:' ": 0.07; 'string': 0.09; 'obj': 0.09; 'subject:None': 0.09; 'subject:Why': 0.09; 'subject:string': 0.09; "wouldn't": 0.14; 'piotr': 0.16; 'received:192.168.0.11': 0.16; 'unbound': 0.16; 'wrote:': 0.18; 'instance,': 0.24; 'subject: : ': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'correct': 0.29; 'am,': 0.29; 'characters': 0.30; 'request,': 0.31; 'prepare': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'sequence': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'sometimes': 0.38; 'message-id:@gmail.com': 0.38; 'to:addr:python- list': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'problems.': 0.60; 'header:Message-Id:1': 0.63; 'field': 0.63; 'more': 0.64; 'subjectcharset:iso-8859-1': 0.66; 'containing': 0.69
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=g9G4enZ/BIondAv0KNPYKfPRadWGMkbS44QkhIn4oCI=; b=efDDRFJdYAALAbYgM0X5XMq1GfBTBN0vn2/Igaz1tzHa1m6rfbjqOq71/7X8H4AB+A rJtTZK7bosqdj+0nGDtU3wUPk1BCUYvdSq7UTJ5Cxjqah08cg3SDb31AptRdsI7AvwDK 6h3Qr+N/F+e4I7ODRp31+LQbtiL03BWf3R9viBk4uiSPQ3r5xwEAHg/IBl0yfy5HO/Tu eSXelmQcXP3JF8fHn5VWkI2p55ra0/d/wzn7+WaL9sKnyHbPpv876W+3mdEOzjfMAByC CouNf7ssSpBDLeWCldpRyjfgdqg3d/KRM/ccT0PNFS3tPXgazsPNsK90LBfWpS6ec0no uyAA==
X-Received by 10.194.19.228 with SMTP id i4mr714571wje.87.1377690179609; Wed, 28 Aug 2013 04:42:59 -0700 (PDT)
Content-Type text/plain; charset=us-ascii
Mime-Version 1.0 (Mac OS X Mail 6.5 \(1508\))
Subject Rép : Why is str(None) == 'None' and not an empty string?
From Fabrice POMBET <fp2161@gmail.com>
In-Reply-To <mailman.2220.1377689401.19983.python-list@python.org>
Date Wed, 28 Aug 2013 13:42:57 +0200
Content-Transfer-Encoding quoted-printable
References <mailman.2220.1377689401.19983.python-list@python.org>
To python-list@python.org
X-Mailer Apple Mail (2.1508)
X-Mailman-Approved-At Wed, 28 Aug 2013 13:44:31 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.304.1377690272.19984.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377690272 news.xs4all.nl 15977 [2001:888:2000:d::a6]:51573
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53134

Show key headers only | View raw


On 8/28/2013 4:57 AM, Piotr Dobrogost wrote:

> Having repr(None) == 'None' is sure the right thing but why does str(None) == 'None'? Wouldn't it be more correct if it was an empty string?

the point of str(obj) is to return a string containing the obj (a sequence of characters if it is unbound or not built-in, etc.)...

If you set the rule str(None)=="", then you will cause plenty of problems. 

For instance, if you want to build a string like request="SELECT X"+"IN Y"+"WHERE B="+String(B)
to prepare a sequel request, and the field B happens to be sometimes "None", you would automatically end up with """SELECT X IN Y WHERE B=''""" instead of """SELECT X IN Y WHERE B='None'""",
and your sql request will fall into limbos...

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Rép : Why is str(None) == 'None' and not an empty string? Fabrice POMBET <fp2161@gmail.com> - 2013-08-28 13:42 +0200

csiph-web