Closed kevinschaul closed 10 years ago
Kevin, this is a really good question, and one worth discussing. The more i think about it, I think we should probably opt for the python dictum that "explicit is better than implicit."
If we're trying to teach investigative reporters how to think about programming and we're going to do whiteboard exercises, we should probably avoid the shortcuts that we like in Python so they're thinking about these steps.
We'll want them to open and close a file rather than using with open
, for instance.
The shebang is probably unnecessary if we're calling these files from python file.py on the command line./
The if name convention is one that could stand in later exercises provided we explain it.
Maybe we should start our first lessons more simply. Thoughts anyone else, like @chrislkeller?
Wait, if you use with open
you don't need to close the file because it does that automatically? Perhaps I should be taking this course :)
I agree with the sentiments above. In putting together the quick scripts I did I struggled with this question as well. Part of me thought well we can save folks from taking circuitous routes, but as well all know those are sometimes the most valuable.
So ditch the if __name__ == '__main__': main()
convention, we'll open and close the file.
Thoughts on using logging
sted of print
? And try/except
? What others?
I didn't know that about with open
either, hah.
I think that try/except
is valuable, but I'm not sure if using a logger is really necessary (since we're focusing on not-web-development).
A lot of "good" code has distracting parts. Which shall we prefer in writing these lessons? Some examples I'm thinking of:
shebang at beginning of file e.g.
#!/usr/bin/env python
differentiate between import and directly running file:
with
for automatically closing files: