single-quoted string conversion to triple-quoted string

Terry Reedy tejarex at yahoo.com
Sat Apr 6 12:08:26 EST 2002


"robin and jim" <robinjim at earthlink.net> wrote in message
news:%_Br8.20276$nt1.1661286 at newsread2.prod.itd.earthlink.net...
>
> Gee, I thought it would be obvious why I was asking such a question
<wink>!

It *is* obvious.  Your question is based on a misunderstanding of
Python which you have so far resisted giving up <wink>!

> Well, yours truly thought he would be clever and add some additional
> information to this docstring as it became available at run time via
the %
> placeholder mechanism.  Alas, the result is a single-quoted string

No, no, no!  There are single-quote string *literals* (what you type)
and triple-quote string *literals*.  Both get translated into internal
string *objects* after *stripping off* the quotes and interpreting (or
not) backslash escapes.  There are also string *expressions* that
yield a string object and other expressions (with variables and/or
function calls) that *might* yield a string object .  A string object
carries with it *no* history of how it was generated.

A string *literal* (regardedless of how quoted!) in the proper place
get stashed with the module/class/function/method object as a __doc__
attribute when that object is *created* (rather than later when
*called*, if callable).  When you got clever and turned the literal
into an *expression*, it was no longer a literal with a value known at
object creation time but an expression with value not known until
later, if ever.  Expressions are not and cannot be used as
automatically-assigned docstrings.  This has NOTHING to do with the
quotedness (or rawness) of the literal.

As Emile van Sebille pointed out in his posting, you must explicit do
any run time manipulation of the docstring yourself.

Terry J. Reedy






More information about the Python-list mailing list