Deleting certain files using python
<p>I have a py script that processes files with extension '.hgx'.Example : test.hgx
( there are many such files with extension hgx)</p>

<p>The script processes the test.hgx and creates a new test_bac.hgx and on re-run it creates test_bac_bac.hgx. So everytime running the script creates a file with <strong>'_bac'.</strong></p>

<p>Is there some solution that I can use in my script that can delete all the existing <strong>'_bac' and '_bac_bac...'</strong> files before start of the actual code.</p>

<p>I am already using glob.glob function</p>

<pre><code>for hgx in glob.glob("*.hgx"):  
</code></pre>

<p>Can I use this function to delete these files 'X_bac.hgx' and other _bac_bac..hgx files?</p>

<p>Any help/idea would be appreciated.</p>

<p>Thanks</p>
