Confused: Newbie Function Calls

Terry Reedy tjreedy at udel.edu
Wed Aug 11 13:35:59 EDT 2010


Rather than patch your code, I think you should see a better approach.

from textwrap import dedent # removes common whitespace prefix

lines = []

def add_header(ss):
     "Add header to sequence of string lines"
     ss.append(dedent("""\ # No initial blank line
     my multi-line
     string here
     """))

def add_more(ss):
     "Add more to sequence of string lines"
     ss.append(dedent(""" # Start with blank line
     another
     multi-line
     string here
     """))

add_header(lines)
add_more(lines)

print(''.join(lines)) # prints
--------------------------------
my multi-line
string here

another
multi-line
string here

--------------------------------

PS. Only use 'gen' for naming generator functions when you get to them.
-- 
Terry Jan Reedy




More information about the Python-list mailing list