Adapted and simplified from Franck Albinet's exercises available here. Also presented by NSRC at APRICOT 2018.
...
For further reference on reading and writing files in Python, look at the official documentation here.
But in In essence to handle files in Python, you first need to open a file (even if it does not exist yet)
Code Block |
---|
python f = open('log/my_first_file.log', 'w') |
the open
function takes as argument: file name 'log/my_first_file.log'
(relative or full path) and mode: read, write, ...
Once open, you get a file object to play with and hence can start writing data in it:
...