In the output of a script that calls Mathematica I would like to be able to differentiate lines printed by mathematica from lines printed by something else. I thought of prefacing lines printed by Mathematica with for example "m:". Is this possible?
Asked
Active
Viewed 99 times
1 Answers
1
As suggested by Szabolcs, I used the Villegas-Gayley method
Unprotect[Print];
Print[args___]:=Block[{$inMsg=True},
Print["|m:>",args,"<:m|"]
]/;!TrueQ[$inMsg]
Protect[Print];
This works well. Ideally I could do the same also for warning messages but I haven't quite figured out yet what the appropriate change would be to Message.
Kvothe
- 4,419
- 9
- 28
-
Just a small comment: you don't need
result, just writePrint["|m:>", args, "<:m|"];. – Domen Jan 16 '23 at 15:41 -
Printbehaves without having to change the code that usesPrint? – Szabolcs Jan 12 '23 at 13:22Printand not change any other part of the code. – Kvothe Jan 12 '23 at 13:24Print? – Szabolcs Jan 12 '23 at 13:40