Printing text in row and column coordinates in Python?

I haven't found anything about this, but maybe because it's not possible. But is there a way to print text in coordinates in Python? For example, if I wanted to print the line "A" in the third and fifth columns of the command window, how could I do it? I've found ways to work around it and print two different lines at different coordinates using \ n for lines and repeating spaces for columns, but this is too tedious to write code.

+3


source to share


2 answers


It is possible. Curses is standard and documented here . There may be others, but they will do what you are looking for. In particular, it curses.getsyx()

might be what you need.



+1


source


If you want to avoid the curses module, you can go to basics using ANSI escape sequences. A brief description of the respective cursor codes can be found here . This works right out of the box on Linux / Unix, for Windows you need the coloroma package .



For a nice cross-platform example using this technique for animation, see here .

+1


source







All Articles