[GRASS-dev] parsing file paths in GRASS Scripts- Windows OS

Glynn Clements glynn at gclements.plus.com
Wed Mar 9 12:29:01 EST 2011


katrin eggert wrote:

> Everytime I try to run a Python Script in Windows, when I need to insert a
> file path (e.g. D:\testing_ground) I need to change the \ for /.

In what context?

In Python string literals, the "\" character is used as an escape
character, e.g. "\n" is newline. You need to use "\\" for a literal
backslash, or use raw string literals, e.g.

	"C:\\Program Files\\GRASS\\..."
or:
	r"C:\Program Files\GRASS\..."

If you're running GRASS commands from a bash shell, bash also uses
backslash as an escape character. The solutions are similar (use a
double backslash or place single quotes around the string), or you can
use cmd.exe instead of bash.

If the issue is elsewhere, you'll need to explain more clearly.

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


More information about the grass-dev mailing list