On Tue, 15 Mar 2005, Tom Lane wrote:

"Sim Zacks" <[EMAIL PROTECTED]> 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.
 _____/ _____/  _/                     [EMAIL PROTECTED]

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
   (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to