Re: [Tutor] Python as Teaching Language
On Sun, 2014-02-09 at 13:36 +, Oscar Benjamin wrote: […] I agree entirely, but what you've overlooked is that my examples are carefully targeted at a particular part of a tutorial-based class. We're talking about iteration so this is quite early in the course. At this stage I want my students to understand that closing a file is an explicit action that needs to occur. Later in the course I will teach exception handling and explain that the above should be rewritten as f = open('myfile.txt') try: for line in f: print(line.upper()) finally: f.close() Shortly after that we will look at using (but not creating) context managers and I'll explain that file objects are also context managers. Works for me. Personally I would ensure I put in forward signposts at the time of covering earlier codes to ensure people realize there is a progression and that the current code is initial not final. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python as Teaching Language
On Mon, 2014-02-10 at 00:17 +, Alan Gauld wrote: […] And in my tutorial I deliberately don't teach many of the standard Python idioms because I'm trying to teach programming rather than Python. So if python has an insanely great way to do stuff but virtually no other language has it I will ignore it. (Or more likely mention it as an aside/footnote.) In the case of file handling and the with statement, indeed any resource management, it is a standard idiom across languages so well worth covering in Python: RAII in C++, ARM in Java, etc. What's interesting (to me) is that I'm currently working on a new project aimed at beginners who have progressed beyond the first steps but are not confident in putting together a bigger program. That is allowing me to address many of the idiomatic aspects of Python that my first book didn't permit. It means that although there is some overlap in coverage the style and content are quite different. Context and target make a big difference in what and how you teach. Definitely. Good luck with the new project. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python as Teaching Language
On Mon, 2014-01-20 at 10:41 +, Oscar Benjamin wrote: […] f = open('myfile.txt') for line in f: print(line.upper()) f.close() I suggest we even see this as not good code due to the possibility of I/O exceptions: with open('myfile.txt') as f: for line in f: print(line.upper()) should, I argue, be the canonical idiom in modern Python. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python as Teaching Language
On 9 February 2014 13:28, Russel Winder rus...@winder.org.uk wrote: On Mon, 2014-01-20 at 10:41 +, Oscar Benjamin wrote: [...] f = open('myfile.txt') for line in f: print(line.upper()) f.close() I suggest we even see this as not good code due to the possibility of I/O exceptions: with open('myfile.txt') as f: for line in f: print(line.upper()) should, I argue, be the canonical idiom in modern Python. I agree entirely, but what you've overlooked is that my examples are carefully targeted at a particular part of a tutorial-based class. We're talking about iteration so this is quite early in the course. At this stage I want my students to understand that closing a file is an explicit action that needs to occur. Later in the course I will teach exception handling and explain that the above should be rewritten as f = open('myfile.txt') try: for line in f: print(line.upper()) finally: f.close() Shortly after that we will look at using (but not creating) context managers and I'll explain that file objects are also context managers. Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python as Teaching Language
On 09/02/14 13:36, Oscar Benjamin wrote: We're talking about iteration so this is quite early in the course. At this stage I want my students to understand that closing a file is an explicit action that needs to occur. Later in the course I will teach exception handling and explain that the above should be rewritten as These are good points. And in my tutorial I deliberately don't teach many of the standard Python idioms because I'm trying to teach programming rather than Python. So if python has an insanely great way to do stuff but virtually no other language has it I will ignore it. (Or more likely mention it as an aside/footnote.) What's interesting (to me) is that I'm currently working on a new project aimed at beginners who have progressed beyond the first steps but are not confident in putting together a bigger program. That is allowing me to address many of the idiomatic aspects of Python that my first book didn't permit. It means that although there is some overlap in coverage the style and content are quite different. Context and target make a big difference in what and how you teach. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python as Teaching Language
On Sun, Jan 19, 2014 at 02:18:54PM -0500, Keith Winston wrote: On Sun, Jan 19, 2014 at 11:55 AM, Alan Gauld alan.ga...@btinternet.com wrote: It has reached the point that I'm back to looking for a new teaching language. In Python 3 the decision has clearly been made to focus on supporting Python's role as a professional software engineering language at the expense of being a successor to ABC or for use in CP4E etc. That's a fair enough decision but it does mean Python is no longer the easiest option for non Comp Sci beginners. It's not worse than the others but it's no longer clearly superior. (IMHO at least! ) But what else is there? that's the problem :-( Hi Alan, since this is off-topic from it's original thread, but I wanted to respond to it, I popped it into a new thread, I hope you don't mind (original was subject iterators). That's the right thing to do. The usual convention is to change the subject line to Python as a teaching language [Was: iterators] so that it's clear from the subject line that you've spawned a new thread from an existing one. Alan, next year I will be teaching a new unit for our first-year Engineering undergrads using Python as an introduction to programming so I've been thinking about these things quite a lot recently. Any language has features that you can't use in an intro course: so just leave them out! If someone wants to spend lots of time learning Python comprehensively then they can do that later. Thankfully you can do a lot in Python without fully understanding its underbelly. As a case in point I don't plan to teach generators or iterators. I will probably broach that subject as follows: In Python there are many types of objects we can loop over with a for statement. We have already seen examples of this with lists and strings e.g.: a = [4, 2, 5] for x in a: ... print(a, 2*a) 4 8 2 4 5 10 Objects that we can loop over are known as iterable. There are other types of objects that are not iterable such as ints and floats: b = 123 for x in b: ... print(b) TypeError: 'int' object is not iterable Note how the error message tells us that this type of object ('int') is not 'iterable'. We've already seen examples of looping over the lines of a text file. It's common in other programming languages to write something like: f = open('myfile.txt') while True: line = f.readline() if not line: # empty string when we get to the end of the file break print(line.upper()) # Do whatever you want with the line here f.close() # Always close the file when done!!! Looping over the lines of a file is so common though that Python has a more convenient version using the fact that a file object is iterable: f = open('myfile.txt') for line in f: print(line.upper()) f.close() One other thing that we need to know here is that some iterables (e.g. lists and strings) can be looped over multiple times whereas file objects can only be looped over once. If you want to loop over the lines of the file again you need to re-open the file (or seek back to the beginning). I would then go on to relate all of the above to list comprehensions. I don't think I'd bother with talking about iterators/iterables and iter/next except in a more advanced Python course. In that course I would also cover generators and other things but for an intro just skip over it. Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python as Teaching Language
On Sun, Jan 19, 2014 at 11:55 AM, Alan Gauld alan.ga...@btinternet.com wrote: It has reached the point that I'm back to looking for a new teaching language. In Python 3 the decision has clearly been made to focus on supporting Python's role as a professional software engineering language at the expense of being a successor to ABC or for use in CP4E etc. That's a fair enough decision but it does mean Python is no longer the easiest option for non Comp Sci beginners. It's not worse than the others but it's no longer clearly superior. (IMHO at least! ) But what else is there? that's the problem :-( Hi Alan, since this is off-topic from it's original thread, but I wanted to respond to it, I popped it into a new thread, I hope you don't mind (original was subject iterators). I can imagine what you mean about a teaching language, and while I don't 1) teach CS or 2) know Python like you do... AND I don't know the alternatives... it still feels like the cleanest, most user-friendly language I've ever worked with. Anyway, there's something to be said for letting novices play with real tools: instead of coming to the end of their one-semester computer class feeling like they just played with legos, they can feel like they got some (minor) feel for building a house. An interesting question is, what's the goal (for those students, probably the majority in a required comp sci course) who aren't going to do a lot of programming in the future ? I can think of a few: help people expand/develop/reflect on their ability to think in various ways; depressurize fear around programming/computers; give them a leg up in approaching the vast range of computer-supported tools in many fields... Anyway, I'm sorta loving this language, and it feels like a decent way in to all of those goals. There are two caveats: one is, without this tutor list (and to a lesser extent, perhaps because I've relied on this so much), other online resources (stack overflow, the Python IRC channels, etc), it would be much harder to make sense of. But those are there, and don't seem in immediate danger of disappearing. And the second... the documentation. I really want to love the documentation, but I can't. I can't maneuver through it hardly at all (if I'm trying to find something in the documentation, I almost always search it from Google), it often doesn't give any examples in the places I want them, and assumes an understanding I don't have at a given moment. I'm SO GRATEFUL to all the people who have contributed to the language, including the documentation, and don't imagine I could do better, I just notice that I haven't figured out how to make it work for me. Now, to a large degree this is not the documentations' fault: I forget things I just read 10s ago, and then I'll charge off to learn a topic far more advanced than I'm reasonably ready for. I have an iterative learning process which involves not understanding a disconcerting amount of what's in front of me. I don't actually think it's optimal, but I literally can't stand (what feels like) the slow, plodding forward approach that is the alternative generally offered. I think there is often a mismatch between teaching structures/approaches, and peoples (very personal, often ill-understood and ill-developed) learning styles. The other thing I wonder about is how to make the learning process more interactive/social: that is, so many of the questions that (even more novice than me) people bring here are things like error statement meanings, etc. In many cases IMO, the first 10 minutes of frustration around something like that can be enough to leave a lasting bad taste. I've gotten some very fast responses around here, and immediate ones on the IRC (which I've only used a little): I believe quick feedback to be crucial to the learning process, and yet we are often trained, in school and elsewhere, to smoulder in frustration around things we don't know yet, I believe (or to just give up and feel stupid)... I don't know whether social platforms will translate to a greater readiness to seek help in order to really learn, or just to learn to fill in the blanks faster/cheat better. Teaching is hard. And a last note on feedback: having the interpreter available is a definite plus for Python, though learning to disassemble one's confusion into little pieces that you can test methodically is hard. But another good skill... Sorry for the length. Keith ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python as Teaching Language
On 19/01/14 19:18, Keith Winston wrote: On Sun, Jan 19, 2014 at 11:55 AM, Alan Gauld alan.ga...@btinternet.com wrote: It has reached the point that I'm back to looking for a new teaching language. ... But what else is there? that's the problem :-( Hi Alan, since this is off-topic from it's original thread, but I wanted to respond to it, I popped it into a new thread, I hope you don't mind (original was subject iterators). Not at all, I probably should have done that myself. I can imagine what you mean about a teaching language, and while I don't 1) teach CS or 2) know Python like you do... AND I don't know the alternatives... it still feels like the cleanest, most user-friendly language I've ever worked with. I agree although I don't teach CS and don't consider myself a Python guru by any means, but I have been programming for 40 years in over 20 languages so I do know a bit about the alternatives! :-) something to be said for letting novices play with real tools: instead of coming to the end of their one-semester computer class feeling like they just played with legos, they can feel like they got some (minor) feel for building a house. Absolutely, and that's why I first chose Python for my tutor. I needed a language that students could go away and actually use for real work - unlike Logo, or even Lisp and Smalltalk. (I know you can do real work in all of those but they are hardly mainstream, and the leap from learning to practicality is quite big IMHO) An interesting question is, what's the goal (for those students, probably the majority in a required comp sci course) who aren't going to do a lot of programming in the future? I hope CS students will be doing a lot of programming! :-) But the target for my tutor was that group who had no formal CS training, and indeed no math training beyond high school, but needed to program to achieve their objectives. Think IT operations staff or sys admins or even non CS academics doing stats etc (This was pre R of course...) So I needed to be able to avoid technical concepts and yet be able to back-fill those concepts when needed. Python did that in v1 and to a lesser degree in v2. But in V3 too many of the academic features seem to escape from the shadows and hit the newbie in the face. fields... Anyway, I'm sorta loving this language, and it feels like a decent way in to all of those goals. I still love Python as a language for my own use. In fact I'm currently working on another book just now that's focused on using Python in practical contexts, but it's not a pure beginners book. And it would be much harder to write a pure beginners book now than it was 15 years ago when I did my first. There is so much more to explain to get quite basic things done. There are two caveats: one is, without this tutor list (and to a lesser extent, perhaps because I've relied on this so much), other online resources (stack overflow, the Python IRC channels, etc), it would be much harder to make sense of. But those are there, and don't seem in immediate danger of disappearing. The internet has changed how people learn. Wikipedia is a fantastic resource for the pure theory type stuff and user fora are great for practical help - although often with as much bad advice as good! Just because something works doesn't make it right! But the days of hunkering down with a single text book and bulldozing your way through are, thankfully, long gone. And the second... the documentation. I really want to love the documentation, but I can't. You should try learning C or Fortran from the DEC VAX manuals! :-) The Python docs are a model of clarity. But you do know how to read them. They are written for professionals. One of the primary targets of my tutor was to explain all of those concepts needed to read the docs and understand them. In that I was only partially successful. (if I'm trying to find something in the documentation, I almost always search it from Google), So does everyone else. Python was created in the internet age. Search engines were assumed to exist and users were expected to use them. it often doesn't give any examples Yes thats one area that could be im[proved. The subprocess model is one exception. I think it would be great if every module page had an accompanying examples page. But no, I'm not volunteering to write them! :-) And there's the rub, everything in Python is done by volunteers. Who wants to spend there day writing examples for a manual page when they could be writing real code? Getting volunteers to document Open Source projects is always a challenge. Python is better served than many. Commercial projects hire professional Technical Authors to wrie the docs and thus tend to be of much higher quality. But you often pay as much for the docs as for the software! learning process which involves not understanding a disconcerting amount of what's in front of me the slow, plodding forward approach that is the