[GRASS-user] g.rename problem with Python
Glynn Clements
glynn at gclements.plus.com
Mon Nov 7 02:09:22 PST 2016
RichardCooper wrote:
> with open('glist_llrotate.txt') as gl:
> for line in gl:
> And the error:
> WARNING: Illegal filename <cahpa.f1jan.05216.nc_remapped.nc.27
> >. Character <
> > not allowed.
When you iterate over a file, the strings include the line terminators
(e.g. '\n' or '\r\n'). Use e.g.
for line in gl:
renamed = line.rstrip().replace('.','_')
...
to remove any trailing whitespace (including newlines) from each line.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list