sekhon.hari at googlemail.com
Tue Jun 27 15:12:25 CEST 2006
Claudio Grondi wrote:
> Hari Sekhon wrote:
>> On 26/06/06, *Claudio Grondi* <claudio.grondi at freenet.de
>> <mailto:claudio.grondi at freenet.de>> wrote:
>> Scott David Daniels wrote:
>> > Claudio Grondi wrote:
>> > <<<clever stuff to di indentation>>>
>> >> When necessary to skip first line _and_ indentation:
>> >> message = """
>> >> This is line 1
>> >> This is line 2
>> >> This is line 3
>> >> """.replace('\n ', '\n')[1:] # adjust here '\n ' to
>> > Riffing on this idea:
>> > message = """
>> > This is line 1
>> > This is line 2
>> > This is line 3
>> > """.replace("""
>> > """, '\n')[1:]
>> This was intended as an excercise for the OP in case he likes
>> that kind
>> of solution ...
>> > --Scott David Daniels
>> > scott.daniels at acm.org <mailto:scott.daniels at acm.org>
>> I've decided to go with
>> message = (
>> "This is line1. "
>> "This is line2 "
>> "This is line3\n")
>> since I'm declaring many different messages inside various functions
>> I feel it is important to keep the indentaion and code both aligned
>> properly so the code looks nice and the output looks nice.
>> It is easier than doing replace and splicing since I want to keep it
>> as simple and clean as possible, in true pythonic tradition...
>> Thanks for the input!
> Thanks for the reply and the explanation what you finally decided to
> go with.
> I am so happy to have the triple quotes in Python, that I use them
> whenever possible - this has probably something to do with my bias
> towards plain text files with human readable content, so as
> readability is very important to me (and probably to many other
> Pythonistas) I like most the proposed by me triple quote style as the
> quotation marks in the style you prefer make the text of the 'message'
> less easy to read.
> Now we can start a flame war about which style is more 'pythonic' ;-)
I already explained that the triple quotes don't work tidily with
indentation, either the code is out of alignment or the printout is.
Either way isn't good.
Triple quotes are best at top level, but since I had to use many
messages inside functions etc, they broke the layout of the code.
I think they're both best depending on where you are putting them. I'm
doing very custom messages for each different result, so it would be
messy to do this at the top level.
More information about the Python-list