Moving from python-checkins and giving this topic a proper subject. The original thread started here with a checkin by Benjamin: http://mail.python.org/pipermail/python-checkins/2008-May/069181.html While Python doesn't have a char type (yet), I still find the distinction between 'c' and "abc" useful to show intent (especially given my C background and occasional but increasingly rare dip into the CPython implementation). I must admit though that I'm not as consistent with this as I used to be or would like to be. I guess that's because I'm lazy and the byte compiler doesn't enforce that style. I do prefer to use """ as the triple quote string delimiter because I find that for most of my uses it makes more sense as apostrophes tend to be the quote chars most frequently embedded in them (I don't do much, if any, HTML these days). This is, of course, all personal preference, and definitely not PEP-8-able. maybe-if-we-<wink>-uncle-timmy-will-sort-it-out-ly y'rs, Skip
skip@pobox.com schrieb:
Moving from python-checkins and giving this topic a proper subject. The original thread started here with a checkin by Benjamin:
http://mail.python.org/pipermail/python-checkins/2008-May/069181.html
While Python doesn't have a char type (yet), I still find the distinction between 'c' and "abc" useful to show intent (especially given my C background and occasional but increasingly rare dip into the CPython implementation). I must admit though that I'm not as consistent with this as I used to be or would like to be. I guess that's because I'm lazy and the byte compiler doesn't enforce that style.
I do prefer to use """ as the triple quote string delimiter because I find that for most of my uses it makes more sense as apostrophes tend to be the quote chars most frequently embedded in them (I don't do much, if any, HTML these days).
This is, of course, all personal preference, and definitely not PEP-8-able.
maybe-if-we-<wink>-uncle-timmy-will-sort-it-out-ly y'rs,
I think some people use the two string literal types to distinguish between text (potentially translatable strings) and data. This way, it's much easier to add i18n later if needed. Georg -- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.
skip@pobox.com wrote:
While Python doesn't have a char type (yet), I still find the distinction between 'c' and "abc" useful to show intent (especially given my C background
The way I tend to use them is that "xxx" is for data operated on by the program and seen by the user, and 'xxx' is for things that are only used internally, e.g. enumerated type values and attribute names for use by getattr(). I wouldn't like to see any guideline that said you should only use double quotes or something like that. -- Greg
Greg> I wouldn't like to see any guideline that said you should only use Greg> double quotes or something like that. It might be useful to have a wiki page which identified some of the conventions people use. Skip
On Sat, May 10, 2008 at 10:51 PM,
It might be useful to have a wiki page which identified some of the conventions people use.
One such entry could be "Do what python does.":
'I am a string.' 'I am a string.' "I'm a string" "I'm a string" -- Benji York
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On May 12, 2008, at 5:16 PM, Benji York wrote:
On Sat, May 10, 2008 at 10:51 PM,
wrote: It might be useful to have a wiki page which identified some of the conventions people use.
One such entry could be "Do what python does.":
'I am a string.' 'I am a string.' "I'm a string" "I'm a string"
Nice. :) - -Barry -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Darwin) iQCVAwUBSCi2mnEjvBPtnXfVAQJWHAP/b/2Yebt7abj+UuysjYFgzetl+26SFSFo jXq/JZUnieIhaiCwMkJW8BW8QmxtkCn3EPDf7VUgMhxMmxDLMQ5Ougzk+/Mq5JLs VM5zJ7kFRU4kBKReGumobSxOMUnteWNYCeUcpUDRHzEEGWFaRM0luNWUiN09iWin DYDvVS5nSCw= =/vGr -----END PGP SIGNATURE-----
Python itself doesn't appear to follow that principle:
"Ain't nothin' stoppin' this from usin' \"double quotes\"." 'Ain\'t nothin\' stoppin\' this from usin\' "double quotes".'
IMHO it's a useful rule of thumb, but like most of the other alternatives
presented in this thread, taken to extremes, it can get silly. (Imagine a
string with 10 's and 9 "s, and adding two more "s to it...) But I suppose
that's another reason these are just guidelines.
Dave Borowitz
On Mon, May 12, 2008 at 5:00 PM,
"Benji" == Benji York
writes: Benji> One such entry could be "Do what python does.":
'I am a string.' 'I am a string.' "I'm a string" "I'm a string"
That would be the principle of fewest backslashes. ;-)
Skip _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/ddborowitz%40gmail.com
-- It is better to be quotable than to be honest. -Tom Stoppard Borowitz
Greg Ewing wrote:
I wouldn't like to see any guideline that said you should only use double quotes or something like that.
Nah, it was more a philosophical discussion prompted by a comment from me regarding my personal reasons for preferring different styles of quotes in certain situations. The various other comments that have come up is that this is one of the cases where having more than one way to do something is a benefit rather than a problem. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org
On Sun, 11 May 2008, Greg Ewing wrote:
While Python doesn't have a char type (yet), I still find the distinction between 'c' and "abc" useful to show intent (especially given my C background
The way I tend to use them is that "xxx" is for data operated on by the program and seen by the user, and 'xxx' is for things that are only used internally, e.g. enumerated type values and attribute names for use by getattr().
I find myself doing something similar. I use '' for anything that is a dictionary key and "" for things that are strings not meant to be used for indexing, in particular the things that are looked up. Except when I don't. When I am generating HTML using the ll.xist library, which uses constructs like this: html.a (u'link text', href="http://url.goes.here/") I have just started using '' for text element contents and "" for attribute values. This way the attribute values (keyword parameters) look almost the exact same as in actual HTML (only difference is the commas) (and the escaping), and my editor seems to be designed for C-style languages where '' are for character constants and "" are for strings so it highlights them differently. My personal opinion is that one should not use the different quoting styles at random, but I am inclined to believe that there is no single guideline that can apply to everybody. Isaac Morland CSCF Web Guru DC 2554C, x36650 WWW Software Specialist
participants (9)
-
Barry Warsaw
-
Benji York
-
David Borowitz
-
Georg Brandl
-
Greg Ewing
-
Isaac Morland
-
Nick Coghlan
-
skip@pobox.com
-
Terry Reedy