+ 1
Is there a way to access output width?
Often when I want to format an output here on sololearn or in other console modes like Windows or QPython, I have different output modalities: Sometimes the line will go on and on and I get a scroll bar, other times there's a forced line break; this break sometimes pushes whole words into the next line or other times cuts them arbitrarily; also the output width differs according to device and/or settings. Consequently, an output, that looks great on my screen, may look like crap on another. Is there a way to access these things via code or even manipulate them? I am thinking of for example something like (pseudo code): x = sys.get_local_screenwidth(unit=letter) print(stuff.center(x-2))
2 Antworten
+ 1
For the 'reading it' part of your query:
This works for me on Android:
dims = os.get_terminal_size()
print(dims.columns, dims.lines)
Here's more on Windows, Linux, cygwin, etc.
(Careful; I haven't tested a recent system--it might be unnecessarily old)
https://gist.github.com/jtriley/1108174
0
Thanks, Kirk!
I tried a bit of the recommendations, but for sololearn no success so far (will try more later).
Unfortunately, os.get_terminal_size() gave me an OSError.
There is a function with the same name in shutil; that one at least returned *something* - not the truth, unfortunately.
I got a width of 80, which is far from what I have on my smarty. I suppose it is the terminal size of the PC, where my attempt was compiled ...
Be careful, Sololearn - pro hacker HonFu is spying you out! :'D
EDIT: QPython has no idea what I want. Pydroid cooperates though!