How to append a string at the end of each line of a string in python?
Question: Let's say, one has stored the stdout of a shell command in a variable. Example
for demonstration:

    
    
    #!/usr/bin/python
    
    import subprocess
    
    proc = subprocess.Popen(['cat', '--help'], stdout=subprocess.PIPE)
    output = proc.stdout.read()
    

Variable `output` now holds content similar to this:

    
    
    Usage: cat [OPTION]... [FILE]...
    Concatenate FILE(s), or standard input, to standard output.
    ...
    For complete documentation, run: info coreutils 'cat invocation'
    

How could one append something to each line besides the last line? So it looks
like the following?

    
    
    Usage: cat [OPTION]... [FILE]...<br></br>
    Concatenate FILE(s), or standard input, to standard output.<br></br>
    ...<br></br>
    For complete documentation, run: info coreutils 'cat invocation'
    

It would be possible to count the line numbers, to iterate through it,
construct a new string and omit appending for the last line... But... Is there
a simpler and more efficient way?


Answer: _"append[ing] a string at the end of each line"_ is equivalent to replacing
each newline with string + newline. Sooo:

    
    
    s = "Usage...\nConcatenate...\n...\nFor complete..."
    t = s.replace("\n", "<br><br>\n")
    print t
    

