Editing Python scripts with Python
<p>I'm trying to permanently edit variables within a Python script' source.</p>

<hr>

<p>e.g.</p>

<pre><code>urlpatterns = patterns('core.views',
)
</code></pre>

<p>to</p>

<pre><code>urlpatterns = patterns('core.views',
    url(r'^admin/', include(admin.site.urls)),
)
</code></pre>

<hr>

<p>e.g.</p>

<pre><code>items = [
    'unicorn',
    'cats',
]
</code></pre>

<p>to</p>

<pre><code>items = [
    'unicorn',
    'cats',
    'knights',
    'panthers',
]
</code></pre>

<hr>

<h3>The problem is capturing the single variable, extending it and replacing it, source of the python file can be quite big and varied.</h3>

<p>This has probably been done already, but cannot seem to find much around.</p>

<p>Any ideas, tips or suggestions?</p>

<hr>

<h2>My solution for now:</h2>

<p>I'm just going to add code at the bottom of the script file</p>

<p>e.g.</p>

<pre><code>urlpatterns += patterns('core.views',
    url(r'^admin/', include(admin.site.urls)),
)
</code></pre>

<p>works for now :)</p>
