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


Groups > comp.lang.python > #53238

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@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; 'api': 0.11; "wouldn't": 0.14; 'bind': 0.16; 'inserting': 0.16; 'parameter.': 0.16; 'piotr': 0.16; 'unbound': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'aug': 0.22; 'instance,': 0.24; 'query': 0.26; 'subject: : ': 0.26; 'pass': 0.26; 'values': 0.27; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'correct': 0.29; 'am,': 0.29; 'characters': 0.30; 'returned': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'context.': 0.31; 'parameters.': 0.31; 'request,': 0.31; 'prepare': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'sequence': 0.36; 'subject:?': 0.36; 'sometimes': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'problems.': 0.60; 'field': 0.63; 'map': 0.64; 'more': 0.64; 'subjectcharset:iso-8859-1': 0.66; 'containing': 0.69; 'attacks.': 0.84; 'irrelevant': 0.84; 'vulnerable': 0.84; '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:from:date:message-id:subject:to :content-type; bh=9eMHuIrY2X3yBEhE0GVrvpL4BL0nECDoVE1r1sai7bE=; b=v8h/tx64js2uADY3hc0GgPrbybiqCQKsMe07+3Z/x06vzezLrIudaofujS9WBJ2mwW Ywt9+kndoLOke/SgSCY0SJHPzL1qooH0ipuVMYqx0M5Zz00UV8krKNKGBHvJ23gHmcOl G4KGmcv50nrBg1CqRpnCGinTd1SdMKGXgZ1X+YMqqenoZ6ZFkt2UP8e9ch7kh0FuFmuK MZLs79Ul7VuPR18DYmfFwjs6Gy88CEuawxd/XCOdL3Xy+hvUQcXW7qfeB6e8dKrAF737 EG4/IUcluKbVR0ZQCQYZY7EGrY+ZDzZNJpHx9xoxKjxSaBfQ2Ci75t/26rd+F/TAiTOM 812w==
X-Received by 10.68.110.98 with SMTP id hz2mr2943007pbb.94.1377773777132; Thu, 29 Aug 2013 03:56:17 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <2C98ABD0-859D-4991-8DE3-CF68A24F136B@gmail.com>
References <mailman.2220.1377689401.19983.python-list@python.org> <2C98ABD0-859D-4991-8DE3-CF68A24F136B@gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 29 Aug 2013 04:55:36 -0600
Subject Re: Rép : Why is str(None) == 'None' and not an empty string?
To Python <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 <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.360.1377775316.19984.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377775316 news.xs4all.nl 15977 [2001:888:2000:d::a6]:51217
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53238

Show key headers only | View raw


On Wed, Aug 28, 2013 at 5:42 AM, Fabrice POMBET <fp2161@gmail.com> wrote:
>
> 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...

The proper way to pass values into a SQL query is by using bind
parameters. Inserting them into the query string by concatenation is
error-prone and an excellent way to write code that is vulnerable to
SQL injection attacks.

The DB API guarantees that the object None will map to the database
value NULL when passed directly as a parameter.  The value returned by
 str(None) is irrelevant in this context.

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


Thread

Re: Rép : Why is str(None) == 'None' and not an empty string? Ian Kelly <ian.g.kelly@gmail.com> - 2013-08-29 04:55 -0600
  Re: Rép : Why is str(None) == 'None' and not an empty string? fp2161@gmail.com - 2013-08-29 13:09 -0700

csiph-web