I'm trying to find the width of the terminal window using python (3.8.2), so that I can store it in a variable. By doing this, I can centre text I display in the terminal, no matter the width of it. As a heads up, I'm using an online IDE called 'repl.it'. Is there a way to find the width of the terminal, or even another way to centre text in the terminal without need for finding its width?
Asked
Active
Viewed 50 times
0
-
80 characters is a safe bet no matter what, usually, as terminals very rarely get smaller than that (and when they do, it's never less than 64 characters IIRC). You can use [`pprint`](https://docs.python.org/3/library/pprint.html) to print a block of text with a defined maximum width. – Green Cloak Guy Jul 20 '20 at 13:54
-
thats perfect. I can use os.get_terminal_size().columns with the os module – KieranLock Jul 20 '20 at 13:54