f



Why """, not '''?

Why is """ the preferred delimiter for multi-line strings?
0
3/5/2008 2:56:24 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

9 Replies
1075 Views

Similar Articles

[PageSpeed] 9

On Mar 5, 9:56 am, MartinRineh...@gmail.com wrote:
> Why is """ the preferred delimiter for multi-line strings?

Is it ? FWIW, I use single quotes whenever I can and double whenever I
have to (i.e. rarely).

George
0
3/5/2008 3:11:30 PM
On Wed, 5 Mar 2008 06:56:24 -0800 (PST)
MartinRinehart@gmail.com wrote:
> Why is """ the preferred delimiter for multi-line strings?

Where did you see that?  The only place I saw it was the style guide
and it was only talking about docstrings.  Even there they used """ as
an example but the text talked about using triple quotes as opposed to
single quotes even when it is a single line docstring.  I don't think
that there is any preference for """ over ''' in general.  Pick one for
consistiency.

Note however that """ can't be confused with " followed by ' as in "'A'
is the first letter of the alphabet."

-- 
D'Arcy J.M. Cain <darcy@druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
0
darcy (332)
3/5/2008 3:13:59 PM

D'Arcy J.M. Cain wrote:
> Where did you see that?  The only place I saw it was the style guide
> and it was only talking about docstrings.

PEP 8 and 257, and you're right, they are both about docstrings.

Also, I'd never seen an example of the triple apostrophe form until I
dove
into the formal syntax specification.
0
3/5/2008 4:40:15 PM
<MartinRinehart@gmail.com> wrote:
> Why is """ the preferred delimiter for multi-line strings?

One advantage is that a dumb syntax highlighter is more likely to cope
well if the content includes an apostrophe.

-M-
0
3/5/2008 7:19:08 PM
On Wed, 05 Mar 2008 19:19:08 +0000, Matthew Woodcraft wrote:

> <MartinRinehart@gmail.com> wrote:
>> Why is """ the preferred delimiter for multi-line strings?
> 
> One advantage is that a dumb syntax highlighter is more likely to cope
> well if the content includes an apostrophe.

But if the content contains double-quote marks, the "dumb syntax 
highligher" is more likely to cope well if you use '''. And, let's be 
realistic here, a "dumb syntax highlighter" is more likely to not cope 
well with triple-quote strings *at all*.

Python treats ' and " symmetrically. There is no difference between them, 
except that:

(1) to type " requires using the shift-key, typing ' does not (on English 
QWERTY keyboards at least);

(2) in some typefaces " (double-quote) may be confused with '' (two 
single-quotes); and

(3) they look different.

Pretty basic stuff really.


-- 
Steven
0
steve9679 (1985)
3/5/2008 9:59:19 PM
Steven D'Aprano  <steve@REMOVE-THIS-cybersource.com.au> wrote:
>On Wed, 05 Mar 2008 19:19:08 +0000, Matthew Woodcraft wrote:
>> One advantage is that a dumb syntax highlighter is more likely to cope
>> well if the content includes an apostrophe.

> But if the content contains double-quote marks, the "dumb syntax 
> highligher" is more likely to cope well if you use '''.

That's right. But apostrophes are rather more common than quote marks
in English text.

> And, let's be realistic here, a "dumb syntax highlighter" is more
> likely to not cope well with triple-quote strings *at all*.

In practice they often do the right thing, what with three being an odd
number.

-M-
0
3/5/2008 11:27:21 PM
On Wed, 05 Mar 2008 23:27:21 +0000, Matthew Woodcraft wrote:

> Steven D'Aprano  <steve@REMOVE-THIS-cybersource.com.au> wrote:
>>On Wed, 05 Mar 2008 19:19:08 +0000, Matthew Woodcraft wrote:
>>> One advantage is that a dumb syntax highlighter is more likely to cope
>>> well if the content includes an apostrophe.
> 
>> But if the content contains double-quote marks, the "dumb syntax
>> highligher" is more likely to cope well if you use '''.
> 
> That's right. But apostrophes are rather more common than quote marks in
> English text.

Surely it would depend on the type of text: pick up any random English 
novel containing dialogue, and you're likely to find a couple of dozen 
pairs of quotation marks per page, against a few apostrophes.



-- 
Steven
0
steve9679 (1985)
3/6/2008 12:07:00 AM
Steven D'Aprano wrote:
> Surely it would depend on the type of text: pick up any random English 
> novel containing dialogue, and you're likely to find a couple of dozen 
> pairs of quotation marks per page, against a few apostrophes.

That's an idea... Write a novel in Python docstrings.

Someone make me go to bed now.
-- 
0
mnordhoff (148)
3/6/2008 1:24:10 AM
On Mar 5, 7:24 pm, Matt Nordhoff <mnordh...@mattnordhoff.com> wrote:
> Steven D'Aprano wrote:
> > Surely it would depend on the type of text: pick up any random English
> > novel containing dialogue, and you're likely to find a couple of dozen
> > pairs of quotation marks per page, against a few apostrophes.
>
> That's an idea... Write a novel in Python docstrings.

Or better yet, write in Python syntax.


assert len([man for man in now_alive() if
man.remembers(datetime.date(1775, 4, 18))]) <= HARDLY

lantern_count = {'land': 1, 'sea': 2}.get(british.location(), 0)
n_ch_twr.hang(Lantern() for _ in xrange(lantern_count))

if lantern_count:
    for village in middlesex:
        ride_thru(village)
        spread_alarm(village)

0
danb_83 (421)
3/6/2008 2:35:12 AM
Reply:

Similar Artilces:

how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ?
--001a11c34e8edbc7c404f6a94bbe Content-Type: text/plain; charset=ISO-8859-1 >>> x=["a","b",["c","d"],"e"] >>> y=x[2] >>> y ['c', 'd'] >>> x.insert(2,y[0]) >>> x ['a', 'b', 'c', ['c', 'd'], 'e'] >>> x.insert(3,y[1]) >>> x ['a', 'b', 'c', 'd', ['c', 'd'], 'e'] >>> del x[4] >>> x ['a', 'b', 'c', 'd', &#...

"Select" & "Order By" OK- ''WHERE'' Does'nt Work !
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've reduced my form request to a simple text string entry, instead of my desired optional parameters. As i have been stuck with a single unfathomable glitch for over a year. Basically, if i enter queries such as ; "select * from table" "select * from table order by artist", it works perfectly. However if i introduce the 'where' option, as in "select * from table where ...

Mandis Quotes (aka retiring """ and ''')
Jef Raskin (namedropping) has pointed me at a neat scheme for quoting arbitrary textual matter called "Mandis quotes". Since google is ignorant of the phrase, I presume that Jef made it up. It is disgustingly simple, and very Pythonesque. Here's how it works: If you have a string that doesn't have any single quotes in it, you surround the string by a pair of doubled single quotes. ''Like this''. No backslash interpolation. If you want a character in there, you put it in there (yes, I know, stand down your armies). Clearly, then, any character except a si...

'quote' to `quote'
Hi, what is the way to change 'shocking,' said Sally into `shocking', said Sally automatically as Tex read the author.txt file? Does this method also change "whatever happens," he said into ``whatever happens.'' he said. David R David R <angel_ov_north@tiscali.co.uk> wrote: > what is the way to change 'shocking,' said Sally > into `shocking', said Sally > automatically as Tex read the > author.txt file? It is possible (e.g. via an active '). But I suspect, this is a lot easier using a script language or similar. Also you ...

(mapcar 'quote '("1" "2" "3" "4"))
(mapcar 'quote '("1" "2" "3" "4")) returns ((quote "4") (quote "4") (quote "4") (quote "4")) Interesting and (for me) unexpected. Because (mapcar 'read '("1" "2" "3" "4")) returns (1 2 3 4) and (mapcar 'princ '("1" "2" "3" "4")) gives 1234("1" "2" "3" "4") Why isn't (mapcar 'quote '("1" "2" "3" "4")) returning ((quote "1") (quote "2") (quote "3") (quote "4")) Tom Haws www.hawsedc.com Probably has to do with the fact that 'arg and (quote arg) are equivalent, and LISP gets confused by the construct 'quote, which is about the same as (quote (quote arg)). But I don't pretend to know all of the mechanics of the error; the results are somewhat different in R14, BTW: Command: (mapcar 'quote '("1" "2" "3" "4")) ((<Subr: #22e3e40> "4") (<Subr: #22e3e40> "4") (<Subr: #22e3e40> "4") (<Subr: #22e3e40> "4")) ___ "Tom Haws" <hawstom@despammed.com> wrote in message news:77317472.0309160733.45ea9d8c@posting.google.com... > (mapcar 'quote '("1" "2" "3"...

=("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'
Hello. Well, I found this piece of code on php.net. Thats fine but where can i find explanation for all these ("|\')?([^ "\']*)("|\')?.*>([^<]*)' syntax so that I can construct my own rules for all kind of eregi preg and oter match functions ? Transform HTML links into plain-text "links" with the URL visible function AHREF2text($string) { return eregi_replace('<A .*HREF=("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>', '[\\4] (link: \\2)', $string); } And another simple question, maybe ...

Re: Mandis Quotes (aka retiring """ and ''')
Russell Nelson wrote: > If you need to put a single quote in, then you put > an arbitrary string in-between the single quotes which does NOT > appear in the string. For example, "Bill's house" becomes > 'x'Bill's house'x'. So possible examples might be: 'xx'somebody's mother'xx' 'xy'somebody's father'xy' 'wink'somebody's uncle'wink' 'quote'somebody's body'quote' not terrible easy on the eyes, and why use the single quote at all? Why no= t use a similar pattern li...

Re: Mandis Quotes (aka retiring """ and ''') #2
Russell Nelson notes: > = > Choose poor examples, and then criticize them as poor choices? > = true enough, but the suggested scheme introduces another variable into the = language syntax; I might always make good choices <wink> on what delimiter = I choose, but I might also end up working on code written by someone else w= ho makes less good choices. Or vice versa. = > Exactly. It really would be better to have one(1) string literal > which can quote anything without reverting to backslashing. Why one? > Simpler parsing, simpler learning of the language, fewe...

expect script : "expect 'X', send 'Y'" until expect "Z".
Hi. I am having some difficulties with an expect script, and was hoping someone could help me out here. I am running a scripted telnet session to some 'black box' appliance, and would like to retrieve the output of a particular command. However, the output of the command is longer than a single screen full. Since it was designed for interactive use, you get the magic string "[=More (xx%)=]" after each screenfull of output, at which point the command expects you to hit the spacebar in order to get another screenfull of output. Of course, I could just "send <space&...

Why doesn't Python's "robotparser" like Wikipedia's "robots.txt" file?
For some reason, Python's parser for "robots.txt" files doesn't like Wikipedia's "robots.txt" file: >>> import robotparser >>> url = 'http://wikipedia.org/robots.txt' >>> chk = robotparser.RobotFileParser() >>> chk.set_url(url) >>> chk.read() >>> testurl = 'http://wikipedia.org' >>> chk.can_fetch('Mozilla', testurl) False >>> The Wikipedia robots.txt file passes robots.txt validation, and it doesn't disallow unknown browsers. But the Python pars...

JAXM returning '&lt;' and '&gt;' rather than "<" and ">"
Hi guys I'm up against a very annoying problem. I'm tryint to use JAXM to call a simple PHP nuSoap web service. I am using SOAPMessage/SOAPPart/SOAPEnvelope etc, however when i receive the message from the server i get: &lt;symbol&gt;great&lt;/symbol&gt; rather than: <symbol>great</symbol> Does anyone have any idea why its converting '<' to '&lt;'??? Any help would be most appreciated, i've been frustrated by this for hours! (Note the xml just dumps out "<symbol>great</symbol>" - it does not encode it ...

[9fans] acme and openning of ", "", '''chk' scripts (by rsc)
------=_Part_63992_24920993.1223483737771 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello, is that an intention that acme does not recognize " (or "", not so sure about '''chk' ) to be a name of a valid file? At least " and "" seems to me to be a valid file name, but clicking on it with button 3 in acme doesn't work --- file is not opened. Only explicit use of Get opens it. Thanks Ruda ------=_Part_63992_24920993.1223483737771 Content-Type: text/html; charset=ISO-8859-1 Content...

what gives with "'import *' not allowed with 'from .'"?
I know the use of "from foo import *" is discouraged, but I'm writing a package that I hope others may want to integrate as a subpackage of their own projects, I know what I'm doing, and I want to use the "from .bar import *" syntax internally. It works fine with python-2.6, but with python-2.5 I get a SyntaxError: "'import *' not allowed with 'from .'" Judging from http://bugs.python.org/issue2400 , this issue was fixed back in May 2008, but it is still present with python-2.5.4, which was released in December. Why wont python-2.5 allow th...

Request " ''BOLD' Error in process BDUGKSH ''NORMAL' "
How could I put bold characters in request command, like this : Request " ''BOLD' Error in process BDUGKSH ''NORMAL' " Thanks in advance. In article <ddf392ea.0311131305.595344d3@posting.google.com>, contracer11@uol.com.br (Shiva MahaDeva) writes: > How could I put bold characters in request command, like this : > > Request " ''BOLD' Error in process BDUGKSH ''NORMAL' " > > Thanks in advance. It depends on what kind of terminal it's going to. In article <ddf392ea.0311131305.595344d3@posting.google.com>, contracer11@uol.com.br (Shiva MahaDeva) writes: >How could I put bold characters in request command, like this : > >Request " ''BOLD' Error in process BDUGKSH ''NORMAL' " Not at all. For security reasons, OPCOM removes nonprintable characters and replaces them by a dot. You want a user to switch your oper terminal in a permanent self test loop ? -- Peter "EPLAN" LANGSTOEGER Network and OpenVMS system specialist E-mail peter@langstoeger.at A-1030 VIENNA AUSTRIA I'm not a pessimist, I'm a realist koehler@eisner.nospam.encompasserve.org (Bob Koehler) writes in article <3vFFBoUQw5N$@eisner.encompasserve.org> dated 13 Nov 2003 16:04:22 -0600: >In article <ddf392ea.0311131305.595344d3@posting.google.com>, contracer11@uol.com.br (Shiva MahaDeva) writes: >> How could I put ...

html dir="rtl" does 'a b c' in same direction as "ltr" but '1 2 3' in different direction
http://www.frostjedi.com/terra/scripts/demo/rtl.html If you view the source, you'll see two divs - <div>a b c</div> and <div>1 2 3</div>. Both are displayed on the right hand side of the screen. <div>a b c</div> renders as 'a b c' but '1 2 3', instead, renders as '3 2 1' and I don't know why. Any ideas? On 2009-02-23, yawnmoth <terra1024@yahoo.com> wrote: > http://www.frostjedi.com/terra/scripts/demo/rtl.html > > If you view the source, you'll see two divs - <div>a b c</div> and &g...

lynx 'browser' can't do "<?xml version="1.0" encoding="utf-8"?>"
lynx is lighteningly fast to fetch a set of pages [via a script] via dump > fileID. But [my current version] doesn't render the 'style' of: "<?xml version="1.0" encoding="utf-8"?>" What is this new "xml" crap ? Will it likely take over the older *.html ? Thanks for any info, == Chris Glur. news@absamail.co.za wrote in news:1172596265.663611@vasbyt.isdsl.net: > lynx is lighteningly fast to fetch a set of pages [via a script] via > dump > fileID. > > But [my current version] doesn't ...

Unable to identify an operator '*=' for types 'character varying[]' and '"unknown"'
Okay.I'm following the documentation that came with the PostgreSQL source code (located in /usr/doc/postgresql-7.3.4-2/html/arrays.hmtl in my cygwin root). I created have a table with a varchar array in it, kind of like the following: CREATE TABLE tbl_db_usuario_detalles (NOMBRE varchar(50), COD_USE varchar(6)[]); I've added a single record that has two values. It is imported from a tab-separated text file that has one line, like the following: Username {xxxxxx,yyyyyy} The import seems to work fine (if I put quotes around the string values in the array it fails). ...

Extend 'enumerate' to "aa", "zz"
I tried to post this before; sorry if it's a repeat. I've got some homework consisting of long lists of short questions, and they're enumerated in the following way: (a), (b), (c), ... (y), (z), (aa), (bb), (cc), ... (yy), (zz), (aaa), (bbb), ... The default behavior for LaTeX's 'enumerate' environment is to choke when it gets to 27 elements in a list enumerated by an expression involving \alph. I'd like to have an environment that would behave the way I just described. I'm sure this is fairly trivial for someone who knows TeX programm...

Q: "my" variables and "no strict 'refs'"
The bottom of p.594 in the Camel book (3rd edition) says this: no strict 'refs'; $name = "variable"; $$name = 7 ; # Sets $variable to 7 ....but I don't obtain that if I declare the variables with "my". Here's my code: no strict 'refs'; my ($variable, $name); $variable = 1; $name = "variable"; $$name = 7; # should set $variable to 7 print "\$variable is $variable\n"; .... and this prints for me: $variable = 1 I've found the code works fine if I don't declare the varia...

"cannot convert parameter from 'short **' to 'void **'"
int func(void**); { short* p = NULL; func(&p); //<<< here } Could somebody remind me why is this not allowed ? error message: "cannot convert parameter from 'short **' to 'void **'" Thanks, Igor On 2005-11-22, Igor Okulist <igor@remove_this_okulist.com> wrote: > int func(void**); > > { > short* p = NULL; > func(&p); //<<< here > } > > Could somebody remind me why is this not allowed ? error > message: "cannot convert parameter from 'short **' to 'void > **'" ...

method="POST" changes '.' to '_'
I am trying to use POST to transfer data to another page. When I do this, '.' characters get converted to"_". For example: #index.html: <form action="test.php" method="post"> <input type="submit" name="filename.txt"> </form> #test.php <html> <?php var_dump( $_POST ); ?> </html> This displays: array(1) { ["filename_txt"]=> string(12) "Submit Query" } ie 'filename.txt' is changed to 'filename_txt' How can I stop this behaviour? On 6 Jul 2006 15:07:59 -070...

Re: Unable to identify an operator '*=' for types 'character varying[]' and '"unknown"'
Okay...I answered my own question. I didn't understand from the directions that I had to compile and install the dll in contrib/array and run the array_iterator.sql. It works like a charm now. Mike -----Original Message----- From: Mike Leahy [mailto:mgleahy@fes.uwaterloo.ca] Sent: October 10, 2003 3:41 PM To: 'pgsql-general@postgresql.org' Subject: Unable to identify an operator '*=' for types 'character varying[]' and '"unknown"' Okay.I'm following the documentation that came with the PostgreSQL source code (located in /u...

Environ("username") / Dev Ashish's "fOSUserName" function return '#Name?' on some clients
I am trying to retrieve the user name (network login) of clients running a local Access DB. We use Access 2000 / 2003 and Windows XP SP 2. I have used 2 different ways to access this information from within Access: OPTION 1: Use Environ("username") OPTION 2: Use Dev Ashish's code (http://www.mvps.org/access/api/ api0008.htm) Both options seem to behave exactly the same for me. But this is my problem: On some clients I correctly retrieve the network login name and on some other clients I retrieve '#Name?'. On ALL clients though, if you you open command prompt and execut...

What is Ruby equivalent of Python's ' if __name__ == "__main__" '
In Python, I can use the test indicated in the subject line to determine if a file is being executed directly, as opposed to being loaded indirectly as the result of the execution of another file. I haven't been able to find the Ruby equivalent of this, and would be most grateful is someone could point me in the right direction. Thanks, Ken McDonald [Note: parts of this message were removed to make it a legal post.] On Wed, Oct 22, 2008 at 11:32 AM, Kenneth McDonald < kenneth.m.mcdonald@sbcglobal.net> wrote: > In Python, I can use the test indicated in the subject l...

Web resources about - Why """, not '''? - comp.lang.python

Resources last updated: 3/4/2016 8:45:13 PM