Greetings
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 /. Of course this is not a problem for me but since I’m trying to put all my colleagues (40s-50 years old colleagues) from my bureau using GRASS and using these scripts this is being a problem. They refuse to use it since they will need to get use to a lot of things (which after a few training sessions Its OK) and they complain with a few things and one of those is this one- File paths are not working on Scripts in Windows. So, I would like to do an efffort to solve this problem and, in this case, contribuuting to ther WinGRASS community.
Has anyone has a tip on how to solve this problem? because It does not recognize the “/” so this character does not even enter in Python Scripts. before It starts to run the python scripts it«s deleted which is a problem?
Any tips or ideas?
Thanks
Katrin
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@gclements.plus.com>
Hello Glynn
First, Thanks for your attention and reply
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?
For instance imagine that I have a python script called r.landsat.py that imports landsat images and do some basic processing. In this case, Landsat file path must be with ‘/’ instead of ''. I know that it«s a simple thing but my bunch of colleagues (old people and used to “easy” tools) are complaining about this because we have built a script and we need to run it a couple of times. I know that the same thing happens with GRASS Bash Scripts.
Yes, I have understand about the ''.
I believe that this is a problem before Python Scripts starts running. I think that this would improve winGRASS usability
Thanks
Kat
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?
For instance imagine that I have a python script called r.landsat.py that
imports landsat images and do some basic processing. In this case, Landsat
file path must be with '/' instead of '\'. I know that it«s a simple thing
but my bunch of colleagues (old people and used to "easy" tools) are
complaining about this because we have built a script and we need to run it
a couple of times. I know that the same thing happens with GRASS Bash
Scripts.
Yes, I have understand about the '\'.
From what you have said, you don't appear to understand.
Python accepts '\'. GRASS typically just passes filenames to the OS,
and Windows accepts '\'.
If you're having problems with '\' in filenames, either you're using
bash (in which case, the solution is either to accept that you have to
conform to bash's syntax or don't use bash), or you've found a bug in
a specific module (in which case, you need to say which one).
--
Glynn Clements <glynn@gclements.plus.com>
Hello Glynn
First of all, thank you for replying to my emails…
Python accepts ''. GRASS typically just passes filenames to the OS,
and Windows accepts ''.
Yes you are right. But for instance, if I try to run r.out.xyz GRASS script (included in WiNGRASS standalone versions) like this: r.out.xyz input=1990@climate output=C:\delete\ai.txt:
- In bash Script it does not place it in c:\delete\ folder but it places in c:\ a file named deleteai.txt. This means that it’s ignoring the ''
- Then, I tried with r.out.xyz Python script adn the same happened.
This happens not only with r.out.xyz but also with other Bash and Python GRASS scripts.THe problem is that, when a user places a path to a file in Scripts GUI (in Windows OS), when it presses the run, “inside the script”, the variable “loses” the ''.
THis is not specific this is for all GRASS Scripts (Bash and Python) that uses filepaths in Windows OS.
Or am I analyzing this wrong?
Katrin Eggert
Hi There
I talked with Helmut, since he is an Win-GRASS expert user, and we have done this test with WinGRASS (Bash Scripts):
r.out.xyz input= output=C:\delete\ai.txt
If I run this in WinGRASS text mode it places the data in file c:\deleteai.txt (it ignores the ''
If I run this in WinGRASS text mode but I place " " around the ouput it runs OK and places the data in c:\delete\ai.txt
If I run this in WinGRASS wxPYTHON GUI it places the data in file c:\deleteai.txt
If I run this in WinGRASS wxPYTHON GUI but I place " " around the the output path it does not run and it get this error:
“C:Deleteai.txt”: No such file or directory
So this is a problem of WxPython in Windows when it gets the file paths and it sends to Scripts (Python or Bash Script)
Any suggestion on how to solve this?
Thanks
Katrin
2011/3/14 katrin eggert <katrineggert1980@gmail.com>
Hello Glynn
First of all, thank you for replying to my emails…
Python accepts ''. GRASS typically just passes filenames to the OS,
and Windows accepts ''.
Yes you are right. But for instance, if I try to run r.out.xyz GRASS script (included in WiNGRASS standalone versions) like this: r.out.xyz input=1990@climate output=C:\delete\ai.txt:
- In bash Script it does not place it in c:\delete\ folder but it places in c:\ a file named deleteai.txt. This means that it’s ignoring the ''
- Then, I tried with r.out.xyz Python script adn the same happened.
This happens not only with r.out.xyz but also with other Bash and Python GRASS scripts.THe problem is that, when a user places a path to a file in Scripts GUI (in Windows OS), when it presses the run, “inside the script”, the variable “loses” the ''.
THis is not specific this is for all GRASS Scripts (Bash and Python) that uses filepaths in Windows OS.
Or am I analyzing this wrong?
Katrin Eggert