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


Groups > comp.lang.python > #106823

Re: one-element tuples

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Stephen Hansen <me+python@ixokai.io>
Newsgroups comp.lang.python
Subject Re: one-element tuples
Date Sun, 10 Apr 2016 18:07:46 -0700
Lines 51
Message-ID <mailman.6.1460336868.15650.python-list@python.org> (permalink)
References <neelcl$mer$1@gioia.aioe.org> <neeq6v$ruk$1@gioia.aioe.org> <neeqnl$sac$2@gioia.aioe.org> <851t6d3s0k.fsf_-_@benfinney.id.au> <mailman.4.1460334906.13861.python-list@python.org> <nees92$u4t$1@gioia.aioe.org> <1460336866.3458680.574656001.1954E9A7@webmail.messagingengine.com>
Mime-Version 1.0
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de z9HF7IcOssLNe8bm/fFaTghLuaXHw2g3qboN/ZgmjIgQ==
Return-Path <me+python@ixokai.io>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'string.': 0.04; 'strings.': 0.07; 'trailing': 0.07; '"a"': 0.09; 'expected.': 0.09; 'received:internal': 0.09; 'tuple': 0.09; 'explicitly': 0.15; "skip:' 30": 0.15; '"b"': 0.16; 'comma.': 0.16; 'commas,': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'quoted': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'received:psf.io': 0.16; 'surprising': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; 'string': 0.17; 'exists': 0.18; '>>>': 0.20; 'saying': 0.22; 'bit': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'otherwise.': 0.27; 'separated': 0.29; "i'm": 0.30; 'is?': 0.33; 'items.': 0.33; 'surprised': 0.33; "skip:' 20": 0.34; 'item': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'two': 0.37; 'expect': 0.37; 'wanted': 0.37; 'received:66': 0.38; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'header:Message- Id:1': 0.61; 'making': 0.62; 'above,': 0.63; 'here': 0.66; 'skip:\xe2 10': 0.70; 'evaluate': 0.72; 'mind:': 0.84; 'today...': 0.84
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=ixokai.io; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=aCENv5L8NGWKbne+U+ekWwcmeIA=; b=ScP4Qw nWanG8RmUtEisOVVGiRAz/7ovpJ0MJD9AZ4eFT9bucZxax6oP07oMaZ6aJWhxWV1 gXVtIdq8Dhze0yKsvVFX8GJTG3JyOOGRWE67lPdVZ+KZNzXuHzduEn4uDjbWC6/9 uIjohREUDwuhl7Sf+KznUuPM2xpWdsJS6UrM8=
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=aCENv5L8NGWKbne +U+ekWwcmeIA=; b=OyASySZS9zBm49Fb8grAzqTdhdpKUKTClH9hGiPZzeeqlq7 SQenRCMyxJuC1CJEEKALKL/ZxSy7xBpUfzoReJn9D79cBVEa8bOOdXq0J4dO//Z9 HNj4eXZvqHuBNNIbHxx9c9JCtGBJAUu7h+RVXwULRnFaqQNH2EBfNpNIrjhc=
X-Sasl-Enc XAHgnKP9dYF5tzLscPZfkA12VljeDCLphogYoDkFIpXl 1460336866
X-Mailer MessagingEngine.com Webmail Interface - ajax-82e6ff7b
In-Reply-To <nees92$u4t$1@gioia.aioe.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
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 <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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <1460336866.3458680.574656001.1954E9A7@webmail.messagingengine.com>
X-Mailman-Original-References <neelcl$mer$1@gioia.aioe.org> <neeq6v$ruk$1@gioia.aioe.org> <neeqnl$sac$2@gioia.aioe.org> <851t6d3s0k.fsf_-_@benfinney.id.au> <mailman.4.1460334906.13861.python-list@python.org> <nees92$u4t$1@gioia.aioe.org>
Xref csiph.com comp.lang.python:106823

Show key headers only | View raw


On Sun, Apr 10, 2016, at 05:48 PM, Fillmore wrote:
> On 04/10/2016 08:31 PM, Ben Finney wrote:
> > Can you describe explicitly what that “discontinuation point” is? I'm
> > not seeing it.
> 
> Here you go:
> 
>  >>> a = '"string1"'

Here, "a" is a string that contains a double quoted string. So if you
evaluate it, you get a string.

>  >>> b = '"string1","string2"'

Here, "b" is a string that contains two double quoted strings separated
by a comma. So if you evaluate it, you get a tuple of two strings.

>  >>> c = '"string1","string2","string3"'

This is as above, but with three items.

With that in mind:
>  >>> ea = eval(a)
>  >>> eb = eval(b)
>  >>> ec = eval(c)
>  >>> type(ea)
> <class 'str'> 
>  >>> type(eb)
> <class 'tuple'>
>  >>> type(ec)
> <class 'tuple'>

This should all be expected. The commas, when you evaluate them, are in
B&C making tuples. There's only a single string in A, so you get a
string. If you wanted a one item tuple, you would have written:

>>> a = '"string1",'

Note the trailing comma.

> I can tell you that it exists because it bit me in the butt today...
> 
> and mind you, I am not saying that this is wrong. I'm just saying that it
> surprised me.

If the above doesn't explain it, then I still don't understand what
you're finding surprising and what you'd expect otherwise.

---Stephen
m e @ i x o k a i . i o

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


Thread

Most probably a stupid question, but I still want to ask Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 18:51 -0400
  Re: Most probably a stupid question, but I still want to ask Chris Angelico <rosuav@gmail.com> - 2016-04-11 08:58 +1000
  Re: Most probably a stupid question, but I still want to ask Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 09:04 +1000
  Re: Most probably a stupid question, but I still want to ask Stephen Hansen <me+python@ixokai.io> - 2016-04-10 16:30 -0700
    Re: Most probably a stupid question, but I still want to ask Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 20:17 -0400
      Re: Most probably a stupid question, but I still want to ask Stephen Hansen <me+python@ixokai.io> - 2016-04-10 17:32 -0700
      Re: Most probably a stupid question, but I still want to ask Terry Reedy <tjreedy@udel.edu> - 2016-04-10 21:45 -0400
        Re: Most probably a stupid question, but I still want to ask Marko Rauhamaa <marko@pacujo.net> - 2016-04-11 08:41 +0300
  one-element tuples [Was: Most probably a stupid question, but I still want to ask] Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 20:13 -0400
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Stephen Hansen <me+python@ixokai.io> - 2016-04-10 17:19 -0700
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Stephen Hansen <me+python@ixokai.io> - 2016-04-10 17:18 -0700
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Chris Angelico <rosuav@gmail.com> - 2016-04-11 10:20 +1000
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 20:22 -0400
      Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Stephen Hansen <me+python@ixokai.io> - 2016-04-10 17:28 -0700
      Re: one-element tuples Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 10:31 +1000
        Re: one-element tuples Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 20:48 -0400
          Re: one-element tuples Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 10:56 +1000
            Re: one-element tuples Grant Edwards <invalid@invalid.invalid> - 2016-04-11 14:10 +0000
              Re: one-element tuples Fillmore <fillmore_remove@hotmail.com> - 2016-04-11 10:11 -0400
                Re: one-element tuples Grant Edwards <invalid@invalid.invalid> - 2016-04-11 14:26 +0000
          Re: one-element tuples Ned Batchelder <ned@nedbatchelder.com> - 2016-04-10 18:00 -0700
          Re: one-element tuples Stephen Hansen <me+python@ixokai.io> - 2016-04-10 18:07 -0700
          Re: one-element tuples "Martin A. Brown" <martin@linux-ip.net> - 2016-04-10 18:08 -0700
            Re: one-element tuples Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 23:19 -0400
              Re: one-element tuples Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-11 09:57 +0300
              Re: one-element tuples Larry Hudson <orgnut@yahoo.com> - 2016-04-11 23:01 -0700
          Re: one-element tuples Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 11:36 +1000
            Re: one-element tuples Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 22:57 -0400
              Re: one-element tuples Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 14:10 +1000
                Re: one-element tuples Fillmore <fillmore_remove@hotmail.com> - 2016-04-11 00:43 -0400
                Re: one-element tuples Stephen Hansen <me+python@ixokai.io> - 2016-04-10 21:54 -0700
                Re: one-element tuples Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 15:40 +1000
                Re: one-element tuples Rustom Mody <rustompmody@gmail.com> - 2016-04-10 22:07 -0700
          Re: one-element tuples BartC <bc@freeuk.com> - 2016-04-11 12:15 +0100
            Re: one-element tuples Marko Rauhamaa <marko@pacujo.net> - 2016-04-11 15:12 +0300
              Re: one-element tuples Grant Edwards <invalid@invalid.invalid> - 2016-04-11 14:12 +0000
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 10:30 +1000
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] MRAB <python@mrabarnett.plus.com> - 2016-04-11 01:33 +0100
      Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Dan Sommers <dan@tombstonezero.net> - 2016-04-11 02:22 +0000
        Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Chris Angelico <rosuav@gmail.com> - 2016-04-11 12:34 +1000
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Chris Angelico <rosuav@gmail.com> - 2016-04-11 10:38 +1000
    Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask]) Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 10:45 +1000
    Re: Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask]) Chris Angelico <rosuav@gmail.com> - 2016-04-11 10:50 +1000
    Re: Parens do create a tuple Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 10:57 +1000
    Re: Parens do create a tuple Chris Angelico <rosuav@gmail.com> - 2016-04-11 11:04 +1000
    Re: Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask]) Stephen Hansen <me@ixokai.io> - 2016-04-10 18:03 -0700
    Re: Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask]) Tim Chase <python.list@tim.thechases.com> - 2016-04-10 19:52 -0500
    Re: Parens do create a tuple Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 11:41 +1000
      Re: Parens do create a tuple Steven D'Aprano <steve@pearwood.info> - 2016-04-11 12:32 +1000
        Re: Parens do create a tuple Random832 <random832@fastmail.com> - 2016-04-10 22:51 -0400
          Re: Parens do create a tuple Steven D'Aprano <steve@pearwood.info> - 2016-04-11 14:08 +1000
            Re: Parens do create a tuple Random832 <random832@fastmail.com> - 2016-04-11 01:27 -0400
              Re: Parens do create a tuple Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-04-11 18:01 +1000
                Re: Parens do create a tuple Random832 <random832@fastmail.com> - 2016-04-11 09:42 -0400
        Re: Parens do create a tuple Chris Angelico <rosuav@gmail.com> - 2016-04-11 13:02 +1000
        Re: Parens do create a tuple Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 14:08 +1000
    Re: Parens do create a tuple Chris Angelico <rosuav@gmail.com> - 2016-04-11 11:51 +1000
      Re: Parens do create a tuple Steven D'Aprano <steve@pearwood.info> - 2016-04-11 12:57 +1000
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Tim Chase <python.list@tim.thechases.com> - 2016-04-10 19:46 -0500
  Re: Most probably a stupid question, but I still want to ask Steven D'Aprano <steve@pearwood.info> - 2016-04-11 11:50 +1000
    Re: Most probably a stupid question, but I still want to ask Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 22:48 -0400
      Re: Most probably a stupid question, but I still want to ask Steven D'Aprano <steve@pearwood.info> - 2016-04-11 13:54 +1000
        Re: Most probably a stupid question, but I still want to ask Fillmore <fillmore_remove@hotmail.com> - 2016-04-11 00:03 -0400
          Re: Most probably a stupid question, but I still want to ask Stephen Hansen <me+python@ixokai.io> - 2016-04-10 21:46 -0700
            Re: Most probably a stupid question, but I still want to ask Rustom Mody <rustompmody@gmail.com> - 2016-04-10 22:18 -0700
              Re: Most probably a stupid question, but I still want to ask Stephen Hansen <me+python@ixokai.io> - 2016-04-10 22:42 -0700
                Re: Most probably a stupid question, but I still want to ask Rustom Mody <rustompmody@gmail.com> - 2016-04-10 23:57 -0700
          Re: Most probably a stupid question, but I still want to ask Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-04-11 17:50 +1000

csiph-web