<div>Hello Glynn</div>
<div> </div>
<div>As soon as I arrive to the office I will give it a try. Thought that I could have global variables such as LC_LANGUAGES and other GRASS_GLOBAL VARIABLES. Is it possible to define them in Init.sh (or .bat) and be used in Python Scripts?</div>
<div> </div>
<div>Best regards,</div>
<div>Kim<br></div>
<div class="gmail_quote">2010/7/5 Glynn Clements <span dir="ltr"><<a href="mailto:glynn@gclements.plus.com" target="_blank">glynn@gclements.plus.com</a>></span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>
<div></div>
<div><br>Kim Besson wrote:<br><br>> I've been testing and "kind of " using GRASS-Python scripts for nearly 2<br>> weeks and it's being great. So far no major issues but now I need to do<br>> something:<br>
> - From a text file (ASCII) I need to read a few variables and make them<br>> global bariables I mean, be available and defined for a huge set of Scripts<br>> in order to avoid to define those variables in each Script. And, in case I<br>
> change them, I only have to change in that ASCII File. My questions are:<br>> 1- How can I do GRASS to read an external File in order to define GLOBAL<br>> VARIABLES?<br>> 2- How can I call them from a GRASS_SCRIPT?<br>
<br></div></div>A "global" variable in Python is local to the module in which it'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>
"import config" (in which case, variables will be accessible as<br>config.whatever) or "from config import *" (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'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("config.cfg")<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 <<a href="mailto:glynn@gclements.plus.com" target="_blank">glynn@gclements.plus.com</a>><br>
</font></blockquote></div><br>