Hi,
I have a search pattern to use as an input list:
--
----
Hi,
I have a search pattern to use as an input list:
--
----
so the pattern returns to the CLI not to the output list "list"
list=g.mlist(type='rast',pattern='interpolation_*') <= not working
Any way to do it?
Thank you,
Yann
On 9 September 2013 12:42, Yann Chemin <ychemin@gmail.com> wrote:
Hi,
I have a search pattern to use as an input list:
--
----
--
----
Hi,
On Mon, Sep 9, 2013 at 3:14 AM, Yann Chemin <ychemin@gmail.com> wrote:
so the pattern returns to the CLI not to the output list “list”
list=g.mlist(type=‘rast’,pattern=‘interpolation_*’) <= not working
Any way to do it?
there is a function in python scripting library [1] and with pygrass you can have a look at [2]. But Pietro can have a better idea, of course.
Anna
[1] http://grass.osgeo.org/programming7/namespacepython_1_1script_1_1core.html#a02c49a538f1d123a07011ab14766d710
[2] https://github.com/lucadelu/workshop-pygrass/blob/master/solutions/00_modules.py
Thank you,
YannOn 9 September 2013 12:42, Yann Chemin <ychemin@gmail.com> wrote:
Hi,
I have a search pattern to use as an input list:
–
–
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev
Hi Yann,
On Mon, Sep 9, 2013 at 8:14 AM, Yann Chemin <ychemin@gmail.com> wrote:
so the pattern returns to the CLI not to the output list "list"
list=g.mlist(type='rast',pattern='interpolation_*') <= not working
it is correct that g.mlist return None, because you are just calling a
GRASS module that write to the stdout and not a python function that
return a python object, therefore you can save the stdout and then
parse it with:
{{{
from grass.pygrass.modules.shortcuts import general as g
import subprocess as sub
gl = g.mlist
gl(type='rast', pattern='elev-*', stdout=sub.PIPE)
gl.outputs.stdout.split()
['elev-000-000', 'elev-000-001', 'elev-000-002', 'elev-001-000',
'elev-001-001', 'elev-001-002', 'elev-002-000', 'elev-002-001',
'elev-002-002']
}}}
or you can use the "glist" method of the Mapset class
{{{
from grass.pygrass.gis import Mapset
m = Mapset()
m.glist('rast', pattern='elev-*')
['elev-002-000', 'elev-000-000', 'elev-000-002', 'elev-000-001',
'elev-001-001', 'elev-002-002', 'elev-002-001', 'elev-001-000',
'elev-001-002']
}}}
that use the "G_list" function through ctypes and therefore is faster.
If you choose the first solution is better if you use directly the
function in python.script.core.mlist_grouped as suggested by Anna.
Best regards
Pietro