Re: Using q() to define a query



From: "Peter J. Holzer" <hjp@xxxxxxxxx>
As an aside, the SPL programming language[2] allows the terminator of a
here document to be indented and to strip off everything up to and
including some character from each line, so that could be written like
this:

function foo() {
some;
code;
here;
if (bla) {
more;
code;
here;
var sql = >>SQL|
|SELECT
| jo.departure_date AS departure
|, eq.name AS equipment
|, dp.full_city AS departure_city
|, ap.full_city AS arrival_city
|, ca.name AS carrier_name
|, jo.number
|[...]
SQL;
even;
more;
}
code;
here;
}

That kinda defeats the purpose of heredocs, namely allowing me to
copy&paste some data into/out of the script without having to escape
or modify anything. If you do this and then need to test and tweak
the SQL in some UI provided by your database you have to go and strip
and later reintroduce the |s. Not for me, I'd rather have a few lines
that are not indented. They are colored differently by my editor so
they stand out anyway. And in this case I can indent them as much as
I like anyway so it's just the terminator ... who the heck cares. The
only time I care is when I increase the indentation of the block
containing the heredoc ... if I could convince my editor to not
indent inside heredocs and the terminator if I select more code I'd
be completely happy.

Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

.



Relevant Pages

  • Re: An idiom for code generation with exec
    ... A simple .strip() doesn't work if the code comprises multiple lines: ... IndentationError: unexpected indent ... In my case I only evaluate function definitions with 'exec', ... for arbitrary code and not only function definitions. ...
    (comp.lang.python)
  • Re: An idiom for code generation with exec
    ... A simple .strip() doesn't work if the code comprises multiple lines: ... IndentationError: unexpected indent ... rejoin. ... Michael Foord ...
    (comp.lang.python)