Here is what I'm trying to do, but the text remain printed in one line. What is wrong?

from grass_session import Session
from grass.script import run_command

with Session(gisdb="path to mygisdb", location="myL72",
             create_opts="EPSG:31370") as sess:

    cptxt = "- first line \n"
    cptxt += "- second line \n"

                at=[2, 45],

But the result is - first line - second line.

Any idea?

  • Try to use \r\n or \r. I'm not sure if it works. Or d.text may not support linefeed (\n). – Kadir Şahbaz Jan 2 at 21:25
  • I'm in a linux environment, normally \n should be enough. I've tried your suggestion, but it does not solve the problem. Thanks anyway. – jean pierre huart Jan 4 at 11:37
  • d.text may not support linefeed (\n). I think that, because for example v.label supports linefeed and this is clearly stated in docs. I think it would have been stated if d.text supported \n. – Kadir Şahbaz Jan 4 at 11:53
  • I'm adapting a bash script that was using version 6.4 and \n was supported. I haven't checked if it is still the case in a bash script, but in python it seems that you are right. I found a workaround using an input file instead. – jean pierre huart Jan 5 at 8:38
  • The best way is to check the source code at github.com/OSGeo/grass/tree/master/display/d.text and propose, as needed, a code improvement. – markusN Jan 5 at 9:49

I've found another way to do it, but I don't find it very elegant. d.text accepts a string or a file. In this second case it works as expected.

cptxt = "- first line \n"
cptxt += "- second line \n"

myfile = 'input_text.txt'

with open(myfile, "w") as ftxt:


I'm still looking if using a string directly is anyway possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.