1
$\begingroup$

My problem is related to FormatType of the Output of Print[].

Look at this example code

i = 4;
Print["Try", "\tPippo : ", i, "\nPluto"]

The output is

enter image description here

If instead I send the output to another stream through

$Output = OpenWrite["demo.txt"] 

and then I evaluate again the Print command, the output in the file “demo.txt” looks like the following

enter image description here

How can I save the text in the same style it appears in Mathematica?

For example, I want my text file to look like enter image description here

$\endgroup$
  • 1
    $\begingroup$ does adding the option FormatType -> OutputForm, that is, using $Output = OpenWrite["demo2.txt", FormatType -> OutputForm] give you what you need? $\endgroup$ – kglr Jan 23 '18 at 16:00
  • $\begingroup$ @kglr Yes!! Thank you! $\endgroup$ – apt45 Jan 23 '18 at 16:30
  • $\begingroup$ I used FormatType -> OutputForm in the Print[] and it didn't work! thank you $\endgroup$ – apt45 Jan 23 '18 at 16:30
  • $\begingroup$ apt45, i posted the comment as an answer. $\endgroup$ – kglr Jan 23 '18 at 16:31
  • $\begingroup$ FYI the reason this is not readily found in the Print documentation is that you normally would use Write for direct writing to files. $\endgroup$ – george2079 Jan 23 '18 at 18:10
2
$\begingroup$

Using

$Output = OpenWrite["demo2.txt", FormatType -> OutputForm]

gives the desired result.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.