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

Glynn Clements glynn at gclements.plus.com
Fri Mar 25 09:32:02 EDT 2011

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).

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-user mailing list