How to capture stdout into a string?

Michael Davis michael at
Sun Jun 9 13:10:30 EDT 2002


I'm using libftp. The FTP.dir() function gets the remote directory listing 
and prints it to standard out. How can I capture that in a string?

If I were using an external process, I know I could open a pipe to it. But 
it's not an external process.

I'm sure there's a tricky way of doing it by getting the file descriptor for 
stdout and reading from it directly, but I was hoping to avoid going that 
low-level. I will if I must though.

Thanks in advance,
Michael Davis
Custom Programming - Web Development - Database Design

More information about the Python-list mailing list