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

Glynn Clements glynn at gclements.plus.com
Sun Jun 10 09:57:05 EDT 2007


Michael Barton wrote:

> I made a python script (rules_colors.py)

Can we see the script?

> following the template on the GRASS WIKI
> 
> <http://grass.gdf-hannover.de/wiki/GRASS_and_Python>

Oh no:

    for arg in sys.argv:
        args += arg+" "

Jesus H %$&%*ing Christ, has no-one read anything I've said over the
past however-many years about argv[] being an array/list, and not a
string?

        os.system("g.parser %s" % (args)) 

Use os.execve().

> I can run the script from the command line...
> 
> python rules_colors.py
> 
> ...and it launches a TclTk GUI.

You're running the command (which command? r.colors?) with no
arguments. For many commands, this will bring up a Tcl/Tk GUI (unless
GRASS_UI_TERM is set, in which case it will use a Q&A dialogue on the
terminal).

This behaviour is hard-coded into G_parser(). If you want to use a
Python GUI, modify your script to invoke the command with
--interface-description and feed that to the Python GUI.

Or modify G_gui() to optionally invoke a wxPython GUI instead of the
Tcl/Tk one.

> When I try to launch it from within the wxPython GUI, it will not launch and
> gives the error...
> 
> IOError: Couldn't fetch interface description for command <rules_colors.py>.
> 
> 
> Indeed if I try to launch it from the command line with...
> 
> python rules_colors.py --interface-description
> 
> ...it gives me an error and does not recognize the ³‹interface-description²
> flag.

Is the Python interpreter trying to process --interface-description
itself? Does:

	python -- rules_colors.py --interface-description

work?

What about:

	chmod +x rules_colors.py
	./rules_colors.py --interface-description

?

[BTW, please use a sane mail client, at least for mailing lists. If
you have to use a Mac-specific encoding (MacRoman?), at least ensure
that it's labelled as such, and not as ISO-8859-1. Although, that in
itself won't affect the fact that it's decided to convert "--" to an
em-dash. If it has a "smart quotes" option, turn it off.]

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




More information about the grass-dev mailing list