Best way of finding terminal width/height?

Grant Edwards grante at visi.com
Tue Feb 7 09:45:07 EST 2006


On 2006-02-07, Joel Hedlund <joel.hedlund at gmail.com> wrote:

> As before, the only IO case above that doesn't throw
> exceptions is the uncommented one. 
>
>> Yup, that's the exception.  Standard practice is to catch it and
>> retry the I/O operation.
>
> Hmm... I guess it's not that easy to "retry" IO operations on
> pipes and streams (stdin/stdout in this case)...

You just call the failed read() or write() again.  Unless
there's some way that the read/write partially succeeded and
you don't have any way to know how many bytes were
read/written, If that's the case then Python's "file" object
read and write would appear to be broken by design.

> And I tend to lean pretty heavily on those since I usually
> write UNIX style text "filters".
>
> So in case I haven't missed something fundamental I guess my
> best option is to accept defeat (of sorts :-) and be happy
> with picking a terminal width at program startup.
>
> But anyway, it's been really interesting trying this out. 
>
> Thank you Grant (och Jorgen) for all help and tips!

-- 
Grant Edwards                   grante             Yow!  BRILL CREAM is
                                  at               CREAM O' WHEAT in another
                               visi.com            DIMENSION...



More information about the Python-list mailing list