[GRASS-user] retrieving a GRASS-python script return values

Daniel Victoria daniel.victoria at gmail.com
Wed Feb 23 19:36:57 EST 2011


>From the error message I take that output_v is a list but the write
command expects a string. So you need to convert your output_v to
string in order to use write.

One trick that I learned recently is how to concatenate values from a
list with using a separator.
1) convert the items in your list to strings:  output_str = [str(i)
for i in output_v]
2) create a string using the join method:  line =
'<separator>'.join(output_str)   -- where <separator> is anything you
choose, comma, space, tab, |
3) write your string

There might be other ways to do this but I found this solution quite easy

Hope it helps
cheers
Daniel

On Wed, Feb 23, 2011 at 9:47 AM, katrin eggert
<katrineggert1980 at gmail.com> wrote:
> hello Glynn
> I'm trying to parse a list of strings like this:
>        sys.stdout.write(output_v)
> And I get this error
> TypeError: argument 1 must be string or read-only character
> buffer, not list
> Any suggestion to do this?
> Thanks
> 2011/2/10 Glynn Clements <glynn at gclements.plus.com>
>>
>> katrin eggert wrote:
>>
>> > I have built a GRASSPy Script to read a few text files (r.in.text.py)
>> > At the end of the file I do a return of a list of integers with:
>> > values=[1,2,4,5,6,43,32,553,2]
>> >
>> > return values
>> >
>> > My question is: I have another GRASS python script that and I want to
>> > call
>> > r.in.text.py to get these values.
>> > What GRASS python functionality shall i use to retrieve these values? (I
>> > suppose grass.run_command is not a good idea).
>>
>> Have r.text.py write the data to stdout, then invoke r.text.py via
>> grass.read_command() or grass.parse_command().
>>
>> For more complex data, you could add an option to r.text.py to write
>> the data in Python's "pickle" format.
>>
>> --
>> Glynn Clements <glynn at gclements.plus.com>
>
>
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
>
>


More information about the grass-user mailing list