with open('status.txt', 'w') as status:
if pin == 1:
status.write('awake')
elif pin == 0:
status.write('sleeping')
Although if pin
could ever potentially be anything else you may want to avoid opening the file unnecessarily.
if pin in [0, 1]:
with open( …