Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Formatting Large Text
    text
    copied!<p>What's the best way to format a large blob of text in python? I don't mean formatting the output, but rather for readability. I've been trying to follow the <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">guidelines for python layout</a>, but I don't see any remarks on how to format a large blob of text.</p> <p>For example:</p> <pre><code>class GenerateCalendar(object): def __init__(self): super( GenerateCalendar, self ).__init__() def getCalendarHeader( self ): print """ BEGIN:VCALENDAR PRODID:-//Atlassian Software Systems//Confluence Calendar Plugin//EN VERSION:2.0 CALSCALE:GREGORIAN X-WR-CALNAME;VALUE=TEXT: X-WR-CALDESC;VALUE=TEXT: """ </code></pre> <p>The large block of text looks terrible and it's not indented by 4 spaces, so it's hard to read.</p> <p>What'd I'd like to see is:</p> <pre><code> def getCalendarHeader( self ): print """ BEGIN:VCALENDAR PRODID:-//Atlassian Software Systems//Confluence Calendar Plugin//EN VERSION:2.0 CALSCALE:GREGORIAN X-WR-CALNAME;VALUE=TEXT: X-WR-CALDESC;VALUE=TEXT: """ </code></pre> <p>but this introduces white space to the beginning of the output.</p> <p>Any ideas on how I can make this follow the recommended layout for python? I'd like to keep it neat and easy to read. </p> <p>Is it possible to do so without doing a print for each line? e.g.</p> <pre><code>def getCalendarHeader( self ): print "BEGIN:VCALENDAR\n" print "PRODID:-//Atlassian Software Systems//Confluence Calendar Plugin//EN\n" print "VERSION:2.0\n" print "CALSCALE:GREGORIAN\n" print "X-WR-CALNAME;VALUE=TEXT:\n" print "X-WR-CALDESC;VALUE=TEXT:\n" </code></pre> <p>The above is the way I'd like to have the code appear, without resorting to doing a print on each line.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload