[GRASS-user] python parse_command

Anna Petrášová kratochanna at gmail.com
Mon Feb 26 06:35:27 PST 2018


Would

parse=(grass.parse_key_val, {'sep': '=', 'vsep': ' '}))

help?

On Mon, Feb 26, 2018 at 4:53 AM, Jonathan Reith <reith at mundialis.de> wrote:
> Ok. So now my code is:
>
>     compregion = grass.parse_command("r.in.xyz", input=xyz,
> separator="space", flags="sg", output="bbox",parse=(grass.parse_key_val,
> {'sep': '='}))
>     print(compregion)
>     g.region(res="1", flags="p", **compregion)
>
> and the output:
>
> {u'n': u'5611999 s=5610000 e=32361999 w=32360000 b=159.04 t=206.46'}
> ERROR: Invalid input <n=5611999 s=5610000 e=32361999 w=32360000 b=159.04
>        t=206.46>
> Traceback (most recent call last):
>   File "grass_scripts/error_script.py", line 40, in <module>
>     main()
>   File "grass_scripts/error_script.py", line 38, in main
>     g.region(res="1", flags="p", **compregion)
>   File
> "/home/jreith/source/grass-7.4.svn/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py",
> line 648, in __call__
>     return self.run()
>   File
> "/home/jreith/source/grass-7.4.svn/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py",
> line 769, in run
>     self.wait()
>   File
> "/home/jreith/source/grass-7.4.svn/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py",
> line 790, in wait
>     module=self.name, errors=stderr)
> grass.exceptions.CalledModuleError: Module run g.region g.region n=5611999
> s=5610000 e=32361999 w=32360000 b=159.04 t=206.46 res=1 -p ended with error
> Process ended with non-zero return code 1. See errors in the (error) output.
> #########################
>
> It seems like my last error disappeared, but now I have a new one.
>
> running < g.region n=5611999 s=5610000 e=32361999 w=32360000 b=159.04
> t=206.46 res=1 -p > from command line in GRASS works just fine.
>
> Any help appreciated
>
> Jonathan
>
>
>
> Am 19.02.2018 um 18:49 schrieb Pietro:
>
> Thank you Anna I did not noticed the underscor...
>
> On 19 Feb 2018 4:41 p.m., "Jonathan Reith" <reith at mundialis.de> wrote:
>
>   print(compregion)
>   g.region(compregion,res="1", flags="p")
>
> you are hassling the dictionary to a region, but you have to unpack the
> dictionary just write:
>
> ...
>
> g.region(res="1", flags="p", **compregion)
>
> the two * unpack the dictionary.
>
> Have fun!
>
> Pietro
>
>
> --
> Studentische Hilfskraft
> mundialis GmbH & Co. KG
> Firmensitz: Kölnstraße 99, 53111 Bonn
> Registergericht: Amtsgericht Bonn, HRA 8528
>
> vertreten durch: mundialis Verwaltungsgesellschaft mbH
> Geschäftsführer:
> Dr. rer. nat. Markus Neteler
> Dipl.-Geogr. Hinrich Paulsen
> Dipl.-Geogr. Till Adams
>
> Tel. +49 (0)228 - 38 75 80 - 80
> Fax. +49 (0)228 - 96 28 99 57
> info [at] mundialis [dot] de
>
> Internet: www.mundialis.de


More information about the grass-user mailing list