Re: python strings

Guido.van.Rossum@cwi.nl
Mon, 25 Apr 1994 17:51:07 +0200

> import sys
>
> S $=
> This is yet another example of a long string. In this
> example the string begins on the line after the $=
> symbol. The string ends with a line containing =$ at the
> beginning of a line, with only whitespace trailing to a
> newline.
> =$
>
> def show_example():
> sys.stdout.write(S)
>
> show_example()
>
> With output:
>
> This is yet another example of a long string. In this
> example the string begins on the line after the $=
> symbol. The string ends with a line containing =$ at the
> beginning of a line, with only whitespace trailing to a
> newline.

Well I can't say I like your choice of tokens (why on earth '$='? Why
the reversed closing quote?) but that's esthetics -- otherwise it
SEEMS not too controversial so far.

> Definition of long strings only allowed outside of function
> definitions & so forth. Assignment or usage is dereferenced at compile
> time, not runtime, to get around the desire to have long strings in
> function w/o a global lookup. If another module imported the above:
>
> import example
> example.S = ''
> example.show_example()
>
> This would output the original message twice. Once a module was
> compiled, if one did not 'del S' in the module, or otherwise assign a
> value to 'S', then the long string would be available in the global
> namespace of the module, though it would act like a normal string.

In one word: EVIL. It would probably require semi-massive change to
the compiler. And the restriction that this construct can only be
used outside function defs is a first for Python (All of 'import',
'class' and 'def' can be used anywhere, conditional, inside methods,
you name it.)

> What I am basically proposing is a syntax, and a optimization with a
> simple side effect.
>
> If you wanted to avoid the side-effect and optimization, you could:
>
> S $=
> A short string or a long string.
> =$
>
> S = S
>
> def show_example():
> sys.stdout.write(S)
>
>
> Here, the runtime value of S would be used.

You are changing the semantics of names in an ad-hoc fashion here.
Why should this be done for strings only? I'd be much happier with a
proposal for a different string quote ONLY.

> The basic goal is to keep ugly strings out of the code...

You could do that with triple quotes by a programming convention.

> If you really like triple quotes (ick ick ick), then gimme a
> compile-time dereference operator. Heck.. give us one anyway. I'd like
> to be able to know that my modules are using the values in their
> globals that I put there, rather than modified ones.
>
> i = 5
>
> def f():
> print *i
>
> i = 6
> f
>
> produces '5'

Actually, there will be a way to do this in 1.0.2 using default
parameters, more or less:

i = 5
def f(i=i):
print i
i = 6

And if you're looking for a language that makes it impossible for
users to pervert the environment in which modules run... Try Ada.

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>