How to capture stdout into a string?

Michael Davis michael at damaru.com
Sun Jun 9 19:10:30 CEST 2002


Hi,

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
Damaru
Custom Programming - Web Development - Database Design
http://www.damaru.com
416-540-1284



More information about the Python-list mailing list