Giving a specific position to cursor in terminal (up-line) after previous line breaks

拟墨画扇 提交于 2021-01-29 05:42:01

问题


I am working on a script to show in the terminal an empty matrix with dot representing all the elements to be filled. Then, I want to ask to the user which element he wants to select for each position.

I had some issues that I couldn't solve with the code given by the professor:
Printing string elements on terminal at certain position.

I have found another way by writting the following code:

for y in range(0, nbLines):
    for x in range(0, nbColumns):
        print("{0}\t".replace('\t', ' ' * 5).format('.'), end='')
        if x == nbColumns -1:
            print('')
            print("\n")

Now, I would like to know if there is a possibility to "go back" to the initial position with my first dot to ask the user to select each coefficient to the matrix ?

When we use \n in print we do a line break, is there any way to reverse it by other print in order to come back to the initial position? In the picture added I would like to come back to the white rectangle.

来源:https://stackoverflow.com/questions/63777617/giving-a-specific-position-to-cursor-in-terminal-up-line-after-previous-line-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!