Appending information to a file to create a log

1,734 views
Skip to first unread message

Henrik L Nordmark

unread,
Mar 5, 2014, 5:16:51 PM3/5/14
to julia...@googlegroups.com
Dear community,

I apologize if this is very trivial, but I haven't been able to figure this out on my own. 

I have been looking in the Julia documentation - especially the Text I/O section - for a way of appending data to a file. I have a for loop for which I would like to append some info to a file at the end of every iteration in order to create a log.

I usually use writecsv(filenameAwhen I am looking to write out data, but that obviously doesn't work in this context as that would simply overwrite a new csv file after every iteration.

If someone could point me in the direction of the correct Julia syntax to append data to a file, that would be greatly appreciated.

Kind regards,
Henrik. 

Jacob Quinn

unread,
Mar 5, 2014, 5:34:24 PM3/5/14
to julia...@googlegroups.com
You need to open the file in "append" mode. See here: http://docs.julialang.org/en/latest/stdlib/base/#Base.open

open(file,"a") do x
    writecsv(x,data)
end

Then write to it, I believe using writecsv or writedlm work fine on open files, but I can't confirm write now; otherwise, you'll need to use the write methods yourself.

-Jacob

Henrik L Nordmark

unread,
Mar 6, 2014, 2:01:36 AM3/6/14
to julia...@googlegroups.com, quinn....@gmail.com
Thanks Jacob that seems to be exactly what I needed!  :-)
Reply all
Reply to author
Forward
0 new messages