From: | Marco Colombo <pgsql(at)esiway(dot)net> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: plpython function problem workaround |
Date: | 2005-03-15 16:27:43 |
Message-ID: | Pine.LNX.4.61.0503151638400.20758@Megathlon.ESI |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, 15 Mar 2005, Tom Lane wrote:
> "Sim Zacks" <sim(at)compulab(dot)co(dot)il> writes:
>> I've been looking at the possibility of having a planned CR in the source
>> code and I don't see a case where it would happen.
>
> Does python actually disallow newlines in string literals? That is
>
> x = 'foo
> bar'
>
> Whether you think this is good style is not the question --- is it
> allowed by the language?
You can with triple-quoting and by escaping it with backslash.
The following code, admitedly ugly, is valid python:
a = 'a\
bc'
print a
b = '''a
bc'''
print b
and produces:
abc
a
bc
as output. \<newline> in any non raw literal is allowed and ignored,
while a bare <newline> in a triple-quoted string literal is allowed
and retained.
Moreover, this is not an execise of bad style only. It's customary to
write docstrings as multiline triple-quoted string literals:
def afunction(a, b, c):
"""This is a function.
Its arguments are:
a - first argument
b - second argument
c - third argument.
It does ans returns nothing.
"""
pass
It's more or less the recommended way to document a function (or class
or module or whatever). See PEP 257 for more examples:
http://www.python.org/peps/pep-0257.html
So, to answer to your question, newlines are more than allowed in
string literals.
.TM.
--
____/ ____/ /
/ / / Marco Colombo
___/ ___ / / Technical Manager
/ / / ESI s.r.l.
_____/ _____/ _/ Colombo(at)ESI(dot)it
From | Date | Subject | |
---|---|---|---|
Next Message | javier wilson | 2005-03-15 16:32:38 | Re: Dump all in several files |
Previous Message | Robert Treat | 2005-03-15 16:17:33 | Re: Postgres jobs mailing list? |