how to calculate the size of sys.stdin?
Chris Gonnerman
chris.gonnerman at usa.net
Wed Apr 11 19:10:46 EDT 2001
----- Original Message -----
From: "Graham Guttocks" <graham_guttocks at yahoo.co.nz>
Subject: how to calculate the size of sys.stdin?
> Greetings,
>
> Is there a way to calculate the size (in bytes) of sys.stdin? I tried
> to use the "stat" module to accomplish this, but os.stat() seems to
> only accept the name of a file. (i.e, the following doesn't work):
>
> import os,stat
> size = os.stat(sys.stdin.read())[stat.ST_SIZE]
What you want is os.fstat():
size = os.fstat(sys.stdin.fileno())[stat.ST_SIZE]
but the result is likely to be meaningless if sys.stdin is
a terminal, pipe, socket, etc.
More information about the Python-list
mailing list