Export an excel file using a variable name in Python
<p>I am new to python, trying to figure out dynamic naming of exported files. Right now, I am exporting an xlsx file in a traditional way:</p>

<p>data_subset.to_csv('Destination/existing_process.csv')</p>

<p>I have a string called 'user_name' and the resultant tuple for every user is exported into an excel file called existing_process. Instead of the name existing_process, I would like to rename the file dynamically using the string user_name. </p>

<p>For instance, for a given user_name 'Matt' I would like the exported file to be named as Matt.csv. Thanks! </p>

<p>You can use <code>string concatenation</code> for that.</p>

<pre><code>name = 'Matt'
with open(name + '.txt', 'w') as f:
    f.write('test')
</code></pre>

<p>The same you can use with <code>xlsx</code> but you will you using it slightly different, but the concatenation process is same. Kindly let me know if you want the exact procedure with <code>xlsx</code></p>

python python-2.7 python-3.x