[GRASS-user] g.remove multiple files in python

Hi,

how to convert something like:

g.remove rast=g.mlist pat=r_start* sep=,

in python?

Thanks!

Margherita DI LEO
Postdoctoral Researcher

European Commission - DG JRC
Institute for Environment and Sustainability (IES). Unit H03 – FRC
Via Fermi, 2749
I-21027 Ispra (VA) - Italy - TP 261

Tel. +39 0332 78 3600
margherita.di-leo@jrc.ec.europa.eu

Disclaimer: The views expressed are purely those of the writer and may not in any circumstance be regarded as stating an official position of the European Commission.

Margherita Di Leo wrote:

how to convert something like:

g.remove rast=`g.mlist pat=r_start* sep=,`

in python?

MaDi,

wouldn't a simple

# get list of r_start* raster maps -- split line-by-line
list_of_r_starts = grass.read_command('g.mlist', type= "rast" , pat =
"r_start*")
r_starts = list_of_r_starts.splitlines()

and then feed "g.mrenove" work for you?

Best, N

ps- sorry, old py-grass read_command in my example.

On 25/01/13 15:28, Margherita Di Leo wrote:

Hi,

how to convert something like:

g.remove rast=`g.mlist pat=r_start* sep=,`

in python?

Try with g.mremove:

grass.run_command('g.mremove', rast='r_start*', flags='f')

Moritz

On Fri, Jan 25, 2013 at 3:46 PM, Moritz Lennert <mlennert@club.worldonline.be> wrote:

On 25/01/13 15:28, Margherita Di Leo wrote:

Hi,

how to convert something like:

g.remove rast=g.mlist pat=r_start* sep=,

in python?

Try with g.mremove:

grass.run_command(‘g.mremove’, rast=‘r_start*’, flags=‘f’)

YESS!
Thanks!

Moritz

Margherita DI LEO
Postdoctoral Researcher

European Commission - DG JRC
Institute for Environment and Sustainability (IES). Unit H03 – FRC
Via Fermi, 2749
I-21027 Ispra (VA) - Italy - TP 261

Tel. +39 0332 78 3600
margherita.di-leo@jrc.ec.europa.eu

Disclaimer: The views expressed are purely those of the writer and may not in any circumstance be regarded as stating an official position of the European Commission.

Hi Margherita,

On Fri, Jan 25, 2013 at 3:28 PM, Margherita Di Leo <diregola@gmail.com> wrote:

Hi,

how to convert something like:

g.remove rast=`g.mlist pat=r_start* sep=,`

in python?

GRASS7: r54769

from pygrass.modules import general as g
from pygrass.gis import Mapset
g.remove(vect=Mapset().glist('vect', pattern='points*'))

Removing vector <points04>
Removing vector <points01>
Removing vector <points02>
Removing vector <points00>
Removing vector <points03>

The method glist, of the Mapset class return a list of maps:

Mapset().glist('vect', pattern='points*')

['points04', 'points01', 'points02', 'points00', 'points03']