Pythonic way to handle updating status string between functions?
<p>This seems like a remedial topic, but I'm a bit unsure of how to deal with this.  Every solution I think of seems messy.</p>

<p>I'm working with some code that builds up a message while performing several actions, then ultimately returns that msg with an http response.  Currently it looks somewhat like this:</p>

<pre><code>try:
    pdict = parser.parseProtocol(id)
    msg = "parsing worked"
except:
    msg = "parsing failed"

try:
    file = parser.getFile(pdict['filePath'])
    msg += "file retrieved"
except:
    msg += "file not found"
</code></pre>

<p>Say I want to encapsulate the code into functions.  How could do I have a message that gets updated throughout?  Strings are immutable, so I can't just pass them to a function and modify them.  A super ugly solution would be:</p>

<pre><code>(pdict, msg) = parseSomething()
if pdict:
    (file, msg) = retrieveFile(pdict, msg)

def parseSomething():
    try:
        pdict = parser.parseProtocol(id)
        return (pdict, "parsing worked")
    except:
        return (None, "parsing failed")

def retrieveFile(pdict, msg)
    try:
        file = parser.getFile(pdict['filePath'])
        return (file, msg + "file retrieved")
    except:
        return (None, msg + "file not found")
</code></pre>

<p>Super ugly.  </p>

<p>I could create a message class, or use a list of length 1, and that would be prettier, but still not very pythonic, right?  I think I just want these functions to take a message string and modify it, without having to return it, but strings are immutable so that's not the default behavior.</p>

<p>There's gotta be a smooth way to do this that I'm just blanking on.  Help?</p>
