What is prefered: 'string' or "string"? (Should be in PEP8 ?)

Philipp Lenssen phil at mrinfo.de
Tue Apr 23 09:42:14 EDT 2002


"Steve Holden" <sholden at holdenweb.com> wrote in message
news:Uscx8.93527$T%5.72611 at atlpnn01.usenetserver.com...
> "Philipp Lenssen" <phil at mrinfo.de> wrote in message
>..
> > For XHTML string output, I prefer single quotes because I don't have to
> > escape double-quotes within the string, e.g.:
> > s += '<img src="..." alt="" />'
> >
>
> For XHTML and HTML output you would find the triple-quoted forms much
> easier. Then you can use EITHER quotes in your output, and include
newlines
> as well, as in:
>
> s = """%s
> <img src="..." alt="A comment">""" % s
>

Yes, for long lines without any variables I do that.
What if you have to do an if-check every second line and dynamic attribute
values?
As you can see it depends on the needs, and the s += '<img .../>' is often
easier.
The more database/ XML driven the XHTML output is in the first place, the
less you will find yourself outputting static portions of XHTML in the first
place.





More information about the Python-list mailing list