[GRASS-dev] Re: [GRASSGUI] silly question - running a python script

Glynn Clements glynn at gclements.plus.com
Mon Jun 11 09:16:55 EDT 2007


Michael Barton wrote:

> >> I forgot, to send the script. Here it is. Doesn't work and I haven't updated
> >> main to use a list. But maybe a starting place for figuring out how to do
> >> scripting with python and GRASS.
> > 
> > If I comment out the "import wx" and "import rules", then both:
> > 
> > python rules_colors.py --interface-description
> > and:
> > chmod +x rules_colors.py
> > ./rules_colors.py --interface-description
> > 
> > work fine. Ditto for --help etc.
> 
> I needed import wx and import rules to launch an interactive window in
> wxPython. I wonder why they cause problems.

I didn't say that they caused problems; I was treating the script as a
normal GRASS script (rather than a wxgrass script), and removing the
imports was simpler than setting up the operating environment to allow
those modules to be imported.

> > That indicates that the use of g.parser is okay.
> > 
> > BTW, what's the point of using:
> > 
> > #!/usr/bin/env python
> > 
> > rather than:
> > 
> > #!/usr/bin/python
> 
> It's that way in the modules in the svn. In the past, I've had trouble with
> the Python shbang on my Mac and so can't really tell which is better. My
> Python is in /usr/bin however.

Calling Python directly is definitely better. If #!/usr/bin/python
doesn't work, you need to fix your system; other Python scripts aren't
going to use that workaround.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list