Envirophat tutorial question


#1

Hi,
In https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-enviro-phat
it mentions:
"
You may also want to add a timestamp to your readings. You can do this with something like the following:

import datetime

timestamp = datetime.datetime.now().isoformat()
"
Well, yes, I do want to timestamp every entry into the log, but I have not figured out how the example provided can help me achieve this.
Basically every time the readings are logged, I want a date and timestamp to be on the same lineā€¦
I have tried adjusting the out.write() to include a strftime string but I get ValueError: unsupported format character y
and when i try to do it in another way:
TypeError: %d format: a number is required not module,
and also:
TypeError: float argument required, not module.
This is the last step to finish my project!


#2

You should definitely read through this:

https://docs.python.org/2/howto/logging-cookbook.html


#3

Thanks, is there a way to get the readings to 2 decimal places?


#4

"{:.2f}".format(1.234567)


#5

Thank you! I found a solution using %.2f