A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-November/058044.html below:

[Python-Dev] indented longstrings?

[Python-Dev] indented longstrings?skip@pobox.com skip at pobox.com
Sat Nov 12 03:56:32 CET 2005
    Avi> Python's longstring facility is very useful, but unhappily breaks
    Avi> indentation. I find myself writing code like

    Avi>     msg = ('From: %s\r\n'
    Avi>            + 'To: %s\r\n'
    Avi>            + 'Subject: Host failure report for %s\r\n'
    Avi>            + 'Date: %s\r\n'
    Avi>            + '\r\n'
    Avi>            + '%s\r\n') % (fr, ', '.join(to), host, time.ctime(), err)
    Avi>     mail.sendmail(fr, to, msg)

This really belongs on comp.lang.python, at least until you've exhausted the
existing possibilities and found them lacking.  However, try:

    msg = ('From: %s\r\n'
           'To: %s\r\n'
           'Subject: Host failure report for %s\r\n'
           'Date: %s\r\n'
           '\r\n'
           '%s\r\n') % (fr, ', '.join(to), host, time.ctime(), err)

or

    msg = ('''\
From: %s
To: %s
Subject: Host failure report for %s
Date: %s

%s
') % (fr, ', '.join(to), host, time.ctime(), err)

or (untested)

    def istring(s):
        return re.sub(r"(\r?\n)\s+", r"\1", s)

    msg = """From: %s
             To: %s
             Subject: Host failure report for %s
             Date: %s

             %s
             """
    msg = istring(msg) % (fr, ', '.join(to), host, time.ctime(), err)

Skip
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4