how to calculate the size of sys.stdin?

Michael Hudson mwh21 at cam.ac.uk
Thu Apr 12 04:19:55 EDT 2001


grante at visi.com (Grant Edwards) writes:

> In article <mailman.987030856.375.python-list at python.org>, Robin Thomas wrote:
> 
> >sys.stdin is more like a pipe, and not a regular file. You
> >can't ask a pipe how many bytes it contains before you read
> >from it.
> 
> Actually, you can.  
> 
> At least on some Unix systems, the FIONREAD ioctl() call will
> tell you how many bytes there are in a pipe waiting to be read.
> IIRC, it also works on some tty devices as well. Probably not
> very portable, and somebody could have shoved more bytes into
> the other end after the ioctl() and before the read(), so you
> could get more that you expect, but you shouldn't get less.

That's interesting for a pet project of mine.  How on earth does one
go about learning things like that?  Is this sort of stuff in Stevens'
APUE?

Cheers,
M.

-- 
  We did requirements and task analysis, iterative design, and user
  testing. You'd almost think programming languages were an interface
  between people and computers.                    -- Steven Pemberton
          (one of the designers of Python's direct ancestor ABC)



More information about the Python-list mailing list