Hi Glynn and rest of the list<div>I have tested this method by creating a config.py and a demo-example of config and I&#39;m not being able to use this solution. Maybe I&#39;m not fully understanding it (never used classes in Python):</div>
<div>1- I create a config1.py file in a working Python directory</div><div>2- I added this to config.py</div><div><div><div>class Params(object):</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>def __init__(self, filename):</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>      params = Params(&quot;config.cfg&quot;)</div></div></div><div>3- My config.cfg has the following:</div><div><div>Ah= &#39;1&#39;</div><div>Bu= &#39;2&#39;</div>
</div><div><br></div><div>4- Just for testing, in a Python Shell I do:</div><div><div>from config1 import Params</div></div><div> (WORK)</div><div>Then:</div><div><div>&gt;&gt;&gt; print Params</div><div>I get: &lt;class &#39;config1.Params&#39;&gt;</div>
</div><div>So I cannot access variables inside config.cfg</div><div>What am I doing wrong?</div><div>Kim</div><div><br></div><div><br></div><div><br></div><div><div class="gmail_quote">2010/7/5 Glynn Clements <span dir="ltr">&lt;<a href="mailto:glynn@gclements.plus.com" target="_blank">glynn@gclements.plus.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div><br>
Kim Besson wrote:<br>
<br>
&gt; I&#39;ve been testing and &quot;kind of &quot; using GRASS-Python scripts for nearly 2<br>
&gt; weeks and it&#39;s being great. So far no major issues but now I need to do<br>
&gt; something:<br>
&gt; - From a text file (ASCII) I need to read a few variables and make them<br>
&gt; global bariables I mean, be available and defined for a huge set of Scripts<br>
&gt; in order to avoid to define those variables in each Script. And, in case I<br>
&gt; change them, I only have to change in that ASCII File. My questions are:<br>
&gt; 1- How can I do GRASS to read an external File in order to define GLOBAL<br>
&gt; VARIABLES?<br>
&gt; 2- How can I call them from a GRASS_SCRIPT?<br>
<br>
</div></div>A &quot;global&quot; variable in Python is local to the module in which it&#39;s<br>
defined. So you you have a module named config, to access any global<br>
variables in that module from other modules you would need either<br>
&quot;import config&quot; (in which case, variables will be accessible as<br>
config.whatever) or &quot;from config import *&quot; (but as the program grows,<br>
the chances of name collisions increase).<br>
<br>
For a set of related variables, e.g. configuration parameters, it&#39;s<br>
usually better to make them all members of a specific object, e.g.:<br>
<br>
        class Params(object):<br>
            def __init__(self, filename):<br>
                # initialise members from file<br>
<br>
        # read the config file<br>
        params = Params(&quot;config.cfg&quot;)<br>
<br>
Then you only need to import a single name:<br>
<br>
        from config import params<br>
<font color="#888888"><br>
--<br>
Glynn Clements &lt;<a href="mailto:glynn@gclements.plus.com" target="_blank">glynn@gclements.plus.com</a>&gt;<br>
</font></blockquote></div><br></div>