[GRASS-user] g.rename problem with Python

I' trying to rename a bunch of imported netCDF layers which include
periods/dots in their filenames. I can rename replacing the '.' with '_' in
the g.rename GUI module, but in Python I get the following errors.

I'd be really grateful for any advice on how to deal with the periods in the
Python script. Alternatively, I could rename before importing into GRASS...

Thanks,
Richard

My script is as follows:

from grass_session import *
...
#Rename layers replacing '.' with '_'
with open('glist_llrotate.txt') as gl:
    for line in gl:
        renamed = line.replace('.','_')
        print 'Renamed layer:', renamed
        grass.run_command('g.rename', raster = (line,renamed), overwrite =
True)
...

And the error:
WARNING: Illegal filename <cahpa.f1jan.05216.nc_remapped.nc.27
         >. Character <
         > not allowed.

The gllist_llrotate.txt file contains content such as:
cahpa.f1jan.05216.nc.1
cahpa.f1jan.05216.nc.10
cahpa.f1jan.05216.nc.11
cahpa.f1jan.05216.nc.12

...

GRASS version: 7.0.1svn
GRASS SVN Revision: 65041
Build Date: 2015-04-10
Build Platform: x86_64-unknown-linux-gnu
GDAL/OGR: 1.11.2
PROJ.4: 4.9.0
GEOS: 3.4.2
SQLite: 3.8.2
Python: 2.7.6
wxPython: 2.8.12.1
Platform: Linux-3.13.0-95-generic-x86_64-with-LinuxMint-17.1-rebecca

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/g-rename-problem-with-Python-tp5294558.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Resolved... was a python error on my side. Corrected now!

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/g-rename-problem-with-Python-tp5294558p5294566.html
Sent from the Grass - Users mailing list archive at Nabble.com.

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@gclements.plus.com>