animal-facts-bot icon indicating copy to clipboard operation
animal-facts-bot copied to clipboard

Cleaning up the code.

Open jac08h opened this issue 7 years ago • 4 comments

Added opening files with context manager. Function in animalfacts.py simplified using elif statement. Fixed typo in README

jac08h avatar Oct 14 '17 20:10 jac08h

@Jac08H I'm not clear on 'with'.

This will maintain all same functionality?

joel-g avatar Oct 23 '17 01:10 joel-g

Yeah, it's just safer way to open files because it closes the file stream in all situations. For example, in your code the files would stay opened if it would throw any kind of exception.

https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

jac08h avatar Oct 29 '17 08:10 jac08h

Assuming conflicts can be sorted this is definitely worth pulling. “With” is worth doing on all your opens

mpentler avatar Jan 30 '18 22:01 mpentler

@joel-g shall we take this one? The with opening method is definitely better, but you should check it to make sure it's all ok. I may not have the time. One for a rainy day :)

mpentler avatar Oct 18 '18 20:10 mpentler