-
Notifications
You must be signed in to change notification settings - Fork 18
Added a section of text about using the with construct. #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The `with` construct is the preferred way of reading and writing files. Among other things it ensures that the files are closed automatically. I also wrote it in a python 2/3 agnostic way.
I'm not sure if this is within the scope of this material, let alone this section. Is the goal of this material to make the learner the best, most idiomatic and best practice data programmer or just teach them how they can solve some interesting data puzzles? I'm at least −0 on having this in the core curriculum. What do you think about an appendix chapter? |
@@ -273,7 +273,25 @@ If you want to try all this out, here's a quick exercise to make sure you've got | |||
|
|||
When writing to the files, remember that `print()` adds a newline but with `write()` you have to add the newline yourself. | |||
|
|||
Hopefully pretty simple, but that should make sure you have all the above ideas down-pat. | |||
Hopefully pretty simple, but you should make sure you have all the above ideas down-pat. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is not from your PR, but while we're at it we could maybe remove the passive-aggressive tone in that? It implies you're somehow not fit as a learner to continue if you did not understand all of this by your heart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. I just jumped in and did this one as 4dc8aa9 (will probably cause a merge conflict, sorry!)
Hi everyone, @jbwhit brought this up in yesterday's workshop in Melbourne, and I suggested he put together a PR. I think the comments raised by @lehmannro are valid too, though. On reflection there is a lot of material and new concepts in this workshop for people who are perhaps only 4 hours into programming (we've found only a small percentage of people make it through the whole of this existing core material in four hours, already.) I like the suggestion of adding these as an Extras section instead, maybe titled "Advanced File Techniques" or "Additional File Techniques". Under the "Why Do You Use Print..." we can link to that discussion as an optional detour. What do you think about trying it that way? |
I think think your comments argues for a very different document than what's currently there (which may be your point). If you are arguing that "writing to a file" is outside the scope of what we want to do, then we should simply remove all "getting text to a file" aspects out of the tutorial. But, I wouldn't argue for that, and I suspect you aren't. Let me know if I have this wrong. So assuming that you want to teach people how to write text to a file: As it stands, the tutorial goes through how to use Instead, I'm arguing for text that says you can use P.S. I don't know what -0 means, but I can guess that it's not supportive. |
One final simple option is:
Disadvantages:
|
@lehmannro do you want me to revise the "writing" to a file section of the webpage to only mention "print"ing to a file and resubmit the pull request? |
I feel mentioning I'd also prefer including the What doing the above, could additionally do is make usage of the |
I support the use of As for the But since then I revised my judgment: we need the learners to understand what they are doing, not just be robots that know a few functions and can't see what is happening behind the I would first introduce the I had the case of one of my developers last week who had a crash due to a related error. He did open files in a loop using with, and put the FILE objects in a list, then returning that list and building a multipart data form with all the FILE objects. Of course his file objects were pointing to closed files outside of his loop, and he couldn't guess why. This anecdote show the relevance of knowing the concepts of opening and closing, that are required even if you use the new Happy easter holiday to those preparing to a long week end Ben. |
Has been fixed recently. |
I'm glad to hear that the Best of luck! |
Don’t worry, we’ll get to the CSV part later in our efforts to update the curriculum 🙂 |
The
with
construct is the preferred way of reading and writingfiles. Among other things it ensures that the files are closed
automatically. I also wrote it in a python 2/3 agnostic way.