Pyladies Intro to Python
Think Python Chp 14 Files http://greenteapress.com/thinkpython/html/thinkpython015.html
Exercise to create a log file
Create a python program
- Create a python program that will create a new file. This program should contain a single function that accepts a file name as a parameter and creates a new file with that name.
Create a second python program that will log
- Create a python module called logging.py
- Create a function that performs the following actions: a) Accepts a single argument that is a string b) Creates a file to write to c) Gets the current date/time d) Creates a string that contains the current date/time and also the message argument e) Writes that string from the previous step to the file create in step b.
Modify your first python program to start logging
- In your first python program, import your logging module
- Instantiate the function from that file in any place in the program you want to log a message