If you want to redirect output from your code, you can use Suppressor.jl, or simply something like this: julia> open("stdout.txt", "w") do ioīut I don’t know if it’s possible to redirect output generated by the REPL. But if you type it in the REPL, your are executing another piece of code: a REPL function that evaluates your code and prints the result. It looks like there’s no solution at all in Julia for such a basic task?.Īs you know I think there are two things to distinguish: In R, there’s just the very simple function sink() to write very easily any REPL output into a file. Output # works, but with a different style than in the REPL And none of those solutions is really satisfying: I let you see that none of those two options universally capture the real REPL output of those very elementary code blocks: sometimes you need a print, sometimes you don’t need it, but there seems to be no means of guessing whether it’s necessary or not. Second try: with the macro from Suppressor.jl, with or without wrapping the whole code block within a print instruction.The loop result 1 2 3 is still printed in the REPL only, and x is not displayed at all (neither in the file nor in the REPL). This creates a file where it’s only written… nothing. Open("/home/fsantos/myfile.txt", "w") do io I would just need that this classical REPL output of such a code block could be written as is, into a file. Let’s say I have the following code block: x = Įveryone can guess waht would be the REPL output. This sounds like a very basic task, but I really can’t find any universal solution in Julia, which sounds just absurd to me. You’ll understand that I need thus a universal solution, which will work for any type of output (dataframe, dict, tuple, array, etc.). My real goal is to retrieve external code blocks (without modifying them) and automatically redirect their REPL output to a given file. However, I still don’t get all the subtleties of Julia I/O… Since I had no answer here, I cross-posted to SO, where I had a great answer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |