Python Gotcha's?
Grzegorz Staniak
gstaniak at gmail.com
Fri Apr 6 10:18:19 EDT 2012
On 06.04.2012, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wroted:
>> Are there languages (other than python) in which single and double
>> quotes are equivalent?
>
> Classic REXX, CSS, JavaScript, Lua, Prolog, XPath, YAML, Modula-2, HTML,
> and (of course) English. There may be others.
>
> Other languages like Perl, PHP and Ruby support alternate delimiters with
> slightly different semantics.
Perl, first of all, has the 'q' and 'qq' operators. As much as I'd
come to dislike Perl after I discovered Python, I miss those two.
Every time I have to quote a string full of single/double quotes,
this comes to my mind:
q{'this' is not this, but 'that' is 'that' like 'this'}
q|'this' is not this, but 'that' is 'that' like 'this'|
q<'this' is not this, but 'that' is 'that' like 'this'>
... with 'qq' providing the version with inerpolation. I could
always find an arbitrary character for quoting that was _not_ present
in the string, and so, most of the time, avoid quoting altogether.
It was perhaps a bit too magical, but pruced very readable strings.
GS
--
Grzegorz Staniak <gstaniak _at_ gmail [dot] com>
More information about the Python-list
mailing list