views:

118

answers:

2

Hi,

Is there something equivalent to Python's StingIO for Clojure?

I'm trying to write a report generating/literate programming system similar to Sweave and Pweave for Clojure. I'm currently using a temp file, but I'd prefer using something similar to StringIO.

+4  A: 

with-out-str is pretty handy.

(let [foo (with-out-str (println "Hello world!"))] 
   foo)

More documentation here

dnolen
having some references embedded in this answer would be nice.
Hamish Grubijan
Thanks, thats exactly what I wanted.
Matti Pastell
+1  A: 

java.io.StringWriter: http://download.oracle.com/javase/6/docs/api/java/io/StringWriter.html

Stuart Sierra