Re: plpython function problem workaround - Mailing list pgsql-general

From Marco Colombo
Subject Re: plpython function problem workaround
Date
Msg-id Pine.LNX.4.61.0503151638400.20758@Megathlon.ESI
Whole thread Raw
In response to Re: plpython function problem workaround  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Tue, 15 Mar 2005, Tom Lane wrote:

> "Sim Zacks" <sim@compulab.co.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@ESI.it

pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Dump all in several files
Next
From: "beyarecords.com"
Date:
Subject: Problems building postgresql 8.0.1 on OS X 10.3.8