[GRASS-user] Running a Pyhton Script on Mac (Mapcalc)

William Kyngesburye woklist at kyngchaos.com
Fri Mar 25 09:47:53 EDT 2011


On Mar 25, 2011, at 8:32 AM, Glynn Clements wrote:

> 
> Johannes Radinger wrote:
> 
>> I opend the script with text wrangler and there were indeed
>> mac line endings. So I saved it with unix line endings and
>> now it seems to work. Maybe GRASS should be able to handle 
>> line endings from various platforms if that is possible...
> 
> 1. The terminator for the #! line must be a bare LF character ('\n',
> '\x0a', decimal 10). This is dealt with by the OS; there isn't
> anything that GRASS can do about it. The interpreter for a script is
> everything following the #! up to the first LF.
> 
> 2. The MacOS X line terminator is LF, the same as Unix. MacOS 9 and
> earlier used CR ('\r', '\x0d', decimal 13). This is one of the many
> things which changed between MacOS 9 and MacOS X.
> 
> 3. Supporting bare CR characters as line terminators is awkward, as
> the code cannot use standard library functions such as fgets(). 
> Supporting CRLF (DOS/Windows format) is somewhat easier, as fgets()
> treats the LF as a line break, and the trailing CR is considered
> whitespace by most C functions (scanf, isspace, etc).
> 
> 4. On platforms where CR is the native line terminator, opening the
> file in "text" mode deals with this. But that doesn't apply to MacOS
> X, where the native line terminator is LF (see #2).
> 

5. And, it's the Python interpreter that handles this, not GRASS.  Though I guess it also depends how you run it.  If you run it with just the script name, the shell needs to find the #! before it passes it off to Python, so it might need the unix LF (and this is also not GRASS, but the shell).  If you run the script from Python, 'python yourscript.py', then Python handles the script file completely.  I thought Python did handle all line endings, but I may be wrong.


-----
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
http://www.kyngchaos.com/

"History is an illusion caused by the passage of time, and time is an illusion caused by the passage of history."

- Hitchhiker's Guide to the Galaxy




More information about the grass-user mailing list