Pythonic way to write many try/except clauses?
<p>I am writing a script to write ~200 cells of somewhat unique data to an excel spreadsheet. My code is following this basic pattern:</p>

<pre><code>try:
    sheet.cell(row=9, column=7).value = getData()
except:
    sheet.cell(row=9, column=7).value = 'NA'
</code></pre>

<p>Basically if there is an error then write some placeholder to the cell. I was wondering if there is a shorter, more pythonic way to write this than having 200 of these in sequence.</p>

<p>As I understand, exception could be occurred in getData() call. So you can wrap getData function as:</p>

<pre><code>def get_data_or_default(default="NA"):
   try:
       return getData()
   except Exception:
       return default
</code></pre>

<p>And then just use:</p>

<pre><code>sheet.cell(row=9, column=7).value = get_data_or_default()
</code></pre>

python excel