Change module __version__ and save the module source file with updated version afterwards
<p>In all of my Python module files I put the module version with <code>__version__</code>.</p>

<p>Now if I release my Python library, I want to increase this module version inside all Python module files automatically. </p>

<p>I know that I can access the version of a module for reading like this:</p>

<p>mymodule.py:</p>

<pre><code># my module
__version__ = "0.0.1"
</code></pre>

<p>usesmymodule.py:</p>

<pre><code>import mymodule

# Gives me "0.0.1"
print mymodule.__version__
</code></pre>

<p>Now how can I save the module source file after I changed its version? In a way like this:</p>

<pre><code>mymodule.__version__ = "0.0.2"
mymodule.__save__() # does not exist as such, but thats what I want
</code></pre>

<p>I could of course apply an sed-like mechanism, reading the source file line by line and replace the <code>__version__</code> - I already have a Bash-script doing that. But I want to replace that Bash-script and increase the module versions in a more Pythonic way. Do you know of any?</p>
