[Python-Dev] str.dedent

Noam Raphael noamraph at gmail.com
Mon Nov 14 23:25:24 CET 2005

On 11/14/05, Fredrik Lundh <fredrik at pythonware.com> wrote:
> so is putting the string constant in a global variable, outside the scope
> you're in, like you'd do with any other constant.

Usually when I use a constant a single time, I write it where I use
it, and don't give it a name. I don't do:

messagea = "The value of A is "

... (a long class definition)
    print messagea, A

This is what I mean when I say "constant" - a value which is known
when I write the code, not necessarily an arbitrary value that may
change, so I write it at the beginning of the program for others to
know it's there.

There's no reason why multilined strings that are used only once
should be defined at the beginning of a program (think about a simple
CGI script, which prints HTML parts in a function.)
> (how about a new rule: you cannot post to a zombie thread on python-
> dev unless they've fixed/reviewed/applied or otherwise processed at least
> one tracker item earlier the same day.  there are hundreds of items on the
> bugs and patches trackers that could need some loving care)
I posted to this thread because it was relevant to a new post about
dedenting strings. Anyway, I looked at bug 1356720 (Ctrl+C for copy
does not work when caps-lock is on), and posted there a very simple
patch which will most probably solve the problem. I also looked at bug
1337987 (IDLE, F5 and wrong external file content. (on error!)). One
problem it raises is that IDLE doesn't have a "revert" command and
that it doesn't notice if the file was changed outside of IDLE. I am
planning to fix it.

The other problem that is reported in that bug is that exceptions show
misleading code lines when the source file was changed but wasn't
loaded into Python. Perhaps in compiled code, not only the file name
should be written but also its modification time? This way, when
tracebacks print lines of changed files, they can warn if the line
might not be the right line.


More information about the Python-Dev mailing list