How to deal with strange errors?
Hi Pythonistas! Im using Python in an educational setting for about a year now and from time to time i'm stumbling (?) over same strange behaviour of IDLE which I consider serious drawbacks in a classroom. One of these is that IDLE cannot react properly to infinite loops. So nothing else but using the Windows taskmanager helps and then reloading everything. Today this occured, when a (quite good) student renamed a loop-variable in the body of a loop during his program development efforts and forgot to do this also in the condition of the while-loop. Ooops. Unfortunately this occured during some sort of exam. Not good! It seems to me that every mistake you can think of also does occur eventually especially when teaching programming. Here I'll report a very special one which occured also during the exam-assignment this afternoon and which the student could not resolve on his own. For me it was interesting, because it did not occur because of a flaw of IDLE but because of a special powerful feature of the language itself. My student wrote this lines: print "Gib jeweils eine Note ein." note = ziffer = durchschnitt = input = ("Wenn du fertig bist, gib 0 ein") eingaben = 0 ziffernsumme = 0 while note > 0: ziffer = note % 10 note = note / 10 Don't think about the meanig of this but look at the syntax error. He got the error message: Gib jeweils eine Note ein. Traceback (most recent call last): File "Z:\6b-20020426\spaula\notendurchschnitt.py", line 10, in ? ziffer = note % 10 TypeError: not all arguments converted Naturally it took him a considerable amount of time to find the cause of this error (which was the = 4 lines above) O.k. he corrected his mistake and tried to rerun his program, this time getting the following error-message: Traceback (most recent call last): File "Z:\6b-20020426\spaula\notendurchschnitt.py", line 6, in ? note = ziffer = durchschnitt = input("Wenn du fertig bist, gib 0 ein") TypeError: 'str' object is not callable k.o.! He could not find out what was - or has been - going on, and even me didn't realize immediately what was the cause of this strange behaviour. Now there occur several questions to me (not in order of importance): 1. What do you do, when errors of this type occur? How do you explain it to students, just beginning to learn programming? 2. How could one develop means, which makes restarting the IDE or the interpreter obsolete? As far as I remember there is a good example in the TeachScheme-Project, where language-features can be turned on/off according to the level of knowledge of the students. One could imagine - in the case obove - to turn off the possibility of overwriting built-in functions in Python ( does there exist a switch concerning this?). 3. Is it possible to rebind input() to it's original built-in function without restarting the whole machinery. 4. Is there a list somewhere of features to implement / provide for educational use of IDLE or some special eduactional-IDE? Or should we start to collect ideas in this direction? My experience tells me (and my opinion is) that it is of crucial importance to have a (nearly) foolprove programming environment when working in school and trying to promote the use of Python. Interestingly it's not so important for the students but much more for the acceptance of the new tool by the majority of the teachers, who already have to learn so many new things concerning all the aspects of computer-science and who because of this show a rather sound(?) amount of inertia when asked to decide for new ways of teaching. (From time to time I do Python courses for teachers here in Vienna). I'm interested in your opinion about these problems and also to contribute to this development, but how? Regards Gregor Lingl
note = ziffer = durchschnitt = input = ("Wenn du fertig bist, gib 0 ^^^^^^^^^
Yes. This doesn't call the input() function at all, but rebinds all those variables to a string. But one question is to ask: is there a reason why all those variables are directed to the same value?
He got the error message:
Gib jeweils eine Note ein. Traceback (most recent call last): File "Z:\6b-20020426\spaula\notendurchschnitt.py", line 10, in ? ziffer = note % 10 TypeError: not all arguments converted
This is an error message that occurs during string formatting. However, I think you're right: this error message doesn't seem descriptive enough for a newcomer to understand what's happening. Even for an intermediate user, this error message doesn't really mention the cause of the error, but only the side effect of it. It might be good to modify the error message to explicitely say something like: "TypeError: not all arguments converted during string formatting" to give a better hint that 'note' here is a string. I've entered a feature request into Sourceforge for this. http://sourceforge.net/tracker/index.php?func=detail&aid=549187&group_id=5470&atid=355470 and perhaps the error message itself can be improved to make the error more clear.
2. How could one develop means, which makes restarting the IDE or the interpreter obsolete? As far as I remember there is a good example in the TeachScheme-Project, where language-features can be turned on/off according to the level of knowledge of the students. One could imagine - in the case obove - to turn off the possibility of overwriting built-in functions in Python ( does there exist a switch concerning this?).
DrScheme will, in fact, warn the user to clear off the previous session if a program has changed. It even has a large RESET button with red letters to make clearing the environment easy to do.
3. Is it possible to rebind input() to it's original built-in function without restarting the whole machinery.
Although 'input' in the global environment is bound to that string now, it's still possible to fix this by going through the __builtin__ module and refix things: ###
input = 'argh' input 'argh' from __builtin__ import * input <built-in function input> ###
That's probably one way of doing it.
4. Is there a list somewhere of features to implement / provide for educational use of IDLE or some special eduactional-IDE? Or should we start to collect ideas in this direction?
The IDLEFork-dev mailing list might be a good place to place to discuss educational issues with IDLE. Good luck to you!
[Danny Yoo]
3. Is it possible to rebind input() to it's original built-in function without restarting the whole machinery.
Although 'input' in the global environment is bound to that string now, it's still possible to fix this by going through the __builtin__ module and refix things:
###
input = 'argh' input 'argh' from __builtin__ import * input <built-in function input> ###
That's probably one way of doing it.
Here is another:
input = 'blah' input 'blah' input = __builtins__['input'] # Note the trailing 's' input <built-in function input>
--- Patrick K. O'Brien Orbtech
On Friday 26 April 2002 10:50 am, you wrote:
[Danny Yoo]
3. Is it possible to rebind input() to it's original built-in function without restarting the whole machinery.
'del' is the easiest.
input = 'argh' input 'argh' del input input <built-in function input>
I'm interested in your opinion about these problems and also to contribute to this development, but how?
Regards Gregor Lingl
I'll repeat an offer I've made on more than one occassion. As the creator of PyCrust, I would be more than happy to work with anyone that wanted to extend its use as a teaching tool. PyCrust is an interactive Python shell and namespace viewer written in Python with the wxPython gui toolkit. PyCrust now ships with wxPython (http://www.wxpython.org). The latest development version is available from CVS at SourceForge (http://sourceforge.net/projects/pycrust). All the foundation work is done. The PyCrust environment can be manipulated like any other Python object and was designed to be modular and extendable. PyCrust has many features that lend themselves to a teaching environment, like autocompletion, calltips, a namespace tree, command recall and full multi-line editing. But it still has most (if not all) of the flaws that were pointed out in this email. I think they are all fixable, but I have a limited amount of time and energy that I can devote to this. What's missing is someone with a little imagination that wanted to take the lead and run with this. Let me know if anyone is interested. --- Patrick K. O'Brien Orbtech
participants (4)
-
Danny Yoo
-
Gregor Lingl
-
Patrick K. O'Brien
-
Richard Wolff