How can I find out how may character are there in a line before the end line in an interactive shell using python? (Usually 80)
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the
tpututility to query the number of lines and columns available in the terminal. You can execute it usingsubprocess.Popen:The same principle can also be applied to query the
$COLUMNSvariable as mentioned by gregseth:Lastly, if you are OK with using the curses library for such a simple problem, as proposed by Ignacio Vazquez-Abrams, then note that you’ll need to perform three statements, not one:
If the terminal is resized, then
setuptermwill need to be called before the new terminal width can be queried usingtigetnum.