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


Groups > comp.lang.python > #7959

Re: What is this syntax ?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '2.7': 0.04; 'instance,': 0.05; 'string,': 0.05; 'character,': 0.07; 'python': 0.08; '>>>>': 0.09; 'chose': 0.09; 'pm,': 0.10; '>>>': 0.12; 'received:209.85.214.174': 0.14; 'received:mail- iw0-f174.google.com': 0.14; 'wrote:': 0.14; 'angelico': 0.16; 'double-quote': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ha!': 0.16; 'posted,': 0.16; 'repr': 0.16; 'repr()': 0.16; 'said.': 0.16; 'string:': 0.16; 'subject:syntax': 0.16; 'header:In-Reply-To:1': 0.21; 'literal': 0.23; 'string': 0.26; 'message-id:@mail.gmail.com': 0.28; 'received:209.85.214': 0.28; 'sun,': 0.30; 'print': 0.31; 'to:addr:python-list': 0.33; "isn't": 0.33; 'chris': 0.34; 'subject: ?': 0.35; 'subject:What': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; 'but': 0.38; 'subject:: ': 0.38; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'simply': 0.60; 'double': 0.62; 'making': 0.67; 'enclosed': 0.68; 'subject:this': 0.76; '"foo"': 0.84; '11:41': 0.84; 'candide': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=j+s8LWpOQQ/0mT28R8mYIzKXpedw4LfP63qrbpO+tR4=; b=Ysc40hb0fThSiUwBGdZZcKIqpJXjjcOzEU+ASrjpDPQXFnI1Bv0WudGS2/Hm0GrUtj qIbc23p3EWhtKaMXsLJi4t9nKqWTXiB99wGc4gzx4tm8JRiKSWoP81DqqRkCw8BEr12W Bq4aEsrIgIFtoF9pu5c4CgDELsaHZ9UIMeejg=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=ub/E3tqrBashQ301F/J0hydH66mP1kSFQlQ8W189kWzdNgwuJVwTjSVNks+DGTlBJi GpZuZz8YsTmixy1vAVRs/IfFfZ3lQFpZENraSrqbWv0mu0zw1CP/v7I/pryYFlTikrzJ QrCUk616JxhR9C3O7+UCHzHLzF1bSuS06gqQc=
MIME-Version 1.0
In-Reply-To <4dfdfc99$0$715$426a34cc@news.free.fr>
References <4dfdfc99$0$715$426a34cc@news.free.fr>
Date Mon, 20 Jun 2011 00:03:31 +1000
Subject Re: What is this syntax ?
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.149.1308492214.1164.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 82.94.164.166
X-Trace 1308492215 news.xs4all.nl 49041 [::ffff:82.94.164.166]:59065
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7959

Show key headers only | View raw


On Sun, Jun 19, 2011 at 11:41 PM, candide <candide@free.invalid> wrote:
> With Python 2.7 :
>
>>>> x="foo"
>>>> print '"'+x+'"'
> "foo"
>>>>

As Laurent posted, it's simply a literal double-quote character,
enclosed in single quotes. But for making a quoted string, this isn't
reliable (what if there's a double quote in the string itself?), so
you may want to try repr() which makes a theoretically evalable
string:

>>> x="foo"
>>> print repr(x)
'foo'

>>> x=raw_input()
"Ha ha! 'Tis mine!", he said.
>>> print repr(x)
'"Ha ha! \'Tis mine!", he said.'

In this instance, repr chose to use single quotes, but the same applies.

Chris Angelico

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


Thread

What is this syntax ? candide <candide@free.invalid> - 2011-06-19 15:41 +0200
  Re: What is this syntax ? Laurent Claessens <moky.math@gmail.com> - 2011-06-19 15:50 +0200
  Re: What is this syntax ? Noah Hall <enalicho@gmail.com> - 2011-06-19 14:58 +0100
  Re: What is this syntax ? Chris Angelico <rosuav@gmail.com> - 2011-06-20 00:03 +1000
  Re: What is this syntax ? candide <candide@free.invalid> - 2011-06-19 17:08 +0200
    Re: What is this syntax ? Roy Smith <roy@panix.com> - 2011-06-19 11:39 -0400
      Re: What is this syntax ? rusi <rustompmody@gmail.com> - 2011-06-19 09:58 -0700
        Re: What is this syntax ? Roy Smith <roy@panix.com> - 2011-06-19 16:20 -0400
          Re: What is this syntax ? Vito 'ZeD' De Tullio <zak.mc.kraken@libero.it> - 2011-06-19 23:06 +0200
            Re: What is this syntax ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-19 23:19 +0000
              Re: What is this syntax ? Vito 'ZeD' De Tullio <zak.mc.kraken@libero.it> - 2011-06-20 07:42 +0200
          Re: What is this syntax ? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-06-19 15:29 -0700

csiph-web