Often it’s very useful being able to write to a from a script, for logging purposes, saving results or as a data store. This is a little snippet on how to write to a .
We use the os package to create the file, exiting the program and logging if it can’t do this and printing a string into the file with Fprintf. We’re also using defer to close the file access once the function has finished running (which is a really neat way of remembering to close files).



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here