change data in Python import file
<p>In my main script, I import some user specific data (another script):<br>
main script:  </p>

<pre><code>.....  
import a lot of things....  
import acemedat  
..... here goes the main code
</code></pre>

<p>the imported file ('acemedat.py'):  </p>

<pre><code># some comment  
azcor = 10        # value can be user dependent  
... some other variables....
</code></pre>

<p>In the main script, I use <strong>acemedat.azcor</strong> and get the value 10 -- fine so far. In the main program, I want to change the value of <strong>azcor</strong>, write it to <strong>acemedat.py</strong>, and save it. The next time I start the main script, the new value is read. I know how to read <strong>acemedat.py</strong> and locate the correct line (I do it with a list of lines read from the file), but it works only with strings. Is there a way to avoid strings and change <strong>azcor</strong> directly?</p>

<p>The file <em>is</em> only strings (well, one big string); what is in that file is used to create the variable you are interested in (amongst other things).</p>

<p>So what you need to do is modify your file to contain the string representation of what you want your variable's value to be, as if you had opened the file in a text editor and typed in the representation of the new value yourself.</p>

python