views:

334

answers:

2

Java's InputStream provides a method named available which returns the number of bytes that can be read without blocking. How can I achieve this in Python?

+3  A: 

You've got to tell us what type of object you're working with. I'm assuming you're talking about a socket read. Either you read the socket with blocking or you read without blocking. You can measure how you have just read in a non-blocking read, if you are interested in that. However, it sounds like you are trying to bend python into a java.io style stream-buffer paradigm that it just doesn't support in detail.

David Berger
+1  A: 

Maybe the answers to this question will help.

Or that link.

To summarize, you could use select, which works for sockets in Windows and for sockets and other files (and pipes) in UNIX.

0x89
I knew about select, but I thought there was another way :)
Geo
Maybe you should add that information to your question the next time?
0x89