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)
Python – how many characters are there in line in a console
pythonshell
Related Topic
- How to mkdir only if a directory does not already exist
- Bash – In the shell, what does ” 2>&1 ” mean
- Python – How to pass a variable by reference
- Python – How to leave/exit/deactivate a Python virtualenv
- Bash – How to echo shell commands as they are executed
- Python – How to read a file line-by-line into a list
- Bash – How to reload .bash_profile from the command line
- Sql – Microsoft Access ADP UPDATE Query does NOT update
Best Answer
You can use the
tput
utility 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
$COLUMNS
variable 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
setupterm
will need to be called before the new terminal width can be queried usingtigetnum
.