[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Why """, not '''?

Martin Rinehart

3/5/2008 2:56:00 PM

Why is """ the preferred delimiter for multi-line strings?
8 Answers

George Sakkis

3/5/2008 3:12:00 PM

0

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

D'Arcy J.M. Cain

3/5/2008 3:14:00 PM

0

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.... | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

Martin Rinehart

3/5/2008 4:40:00 PM

0



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.

Matthew Woodcraft

3/5/2008 7:19:00 PM

0

<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-

Steven D'Aprano

3/5/2008 9:59:00 PM

0

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

Matthew Woodcraft

3/5/2008 11:27:00 PM

0

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-

Steven D'Aprano

3/6/2008 12:07:00 AM

0

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

Matt Nordhoff

3/6/2008 1:24:00 AM

0

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.
--