From cmeyers@guardnet.com Fri Mar 1 17:18:48 2002 From: cmeyers@guardnet.com (Chris Meyers) Date: Fri, 01 Mar 2002 09:18:48 -0800 Subject: [Edu-sig] OnLisp Message-ID: Thanks for the tip Dethe. I've got the book downloaded and it looks like a real gem. That many of the special things you can do in Lisp can also be done in Python, makes this book especially valuable for this community. Chris 02/26/2002 9:41:38 AM, Dethe Elza wrote: >You can download Paul Graham's out-of-print book On Lisp. I found out >about this from an interesting weblog called "Everything Burns" >(http://jimfl.tensegrity.net/), which had this to say about it: > > >I esteem OnLisp to be one of the most well-written, compelling books I >have encountered on any topic in computing. This is no mean praise >considering various works by one Stanford Professor name of Knuth. You >don't really have to care much about Lisp or its variants to enjoy this >book, though you should, at least, be able to tolerate topics which >arise from the peculiarities in Lisp-shaped languages. Familiarity with >Lisp will serve a programmer in any language anyway. > >Sadly, OnLisp is out of print, but you can download it free of charge. >You will be missing only the weight of the dense paperback in your >hands, the attractive cover, and the few figures sprinkled throughout. > > >http://www.paulgraham.com/onlisptext.html > >--Dethe > >-- >Dethe Elza (delza@burningtiger.com) >Chief Mad Scientist >Burning Tiger Technologies (http://www.burningtiger.com) >Weblog: http://livingcode.manilasites.com/ > > >_______________________________________________ >Edu-sig mailing list >Edu-sig@python.org >http://mail.python.org/mailman/listinfo/edu-sig > From delza@mac.com Sat Mar 2 02:05:41 2002 From: delza@mac.com (Dethe Elza) Date: Fri, 1 Mar 2002 18:05:41 -0800 Subject: [Edu-sig] OnLisp In-Reply-To: Message-ID: You're quite welcome. I'm learning Squeak (Smalltalk) right now to improve my Python skills, some flavor of functional programming is next on the list. I just started reading "The Pragmatic Programmer" (a really great book so far--highly recommended) and one of the first challenges in chapter one is to learn another language -- and Squeak is given as an example. Interestingly enough I'd just finished installing Squeak to help me review the book "Squeak: A Quick Trip to ObjectLand," co-authored by my buddy Doug Dechow (review coming soon). Sometimes I really like the way the world works. %-) Happy Baba Marta (Bulgarian March First holiday)! --Dethe On Friday, March 1, 2002, at 09:18 AM, Chris Meyers wrote: > Thanks for the tip Dethe. I've got the book downloaded and it looks > like a real gem. That many of the special things you can > do in Lisp can also be done in Python, makes this book especially > valuable for this community. > > Chris > -- Dethe Elza (delza@burningtiger.com) Chief Mad Scientist Burning Tiger Technologies (http://www.burningtiger.com) Weblog: http://livingcode.manilasites.com/ From ajs@ix.netcom.com Sat Mar 2 16:18:51 2002 From: ajs@ix.netcom.com (Arthur Siegel) Date: Sat, 2 Mar 2002 11:18:51 -0500 Subject: [Edu-sig] Algorithm help Message-ID: <000001c1c206$3d154140$3354f6d1@ArtsPortable> Having inititally thought that asking for advice on algorithms was a bit OT for edu-sig and it more appropriate to go to the vast web for resources, I do a Google on "permutations algorithm" and get back as hit #1 a posting here by Kirby from May 1991. Great. So I click my ruby (small "r") slippers. My geometry meanderings have more and more (and somewhat unexpectedly) led me into needing algorithms related to permutations and subsets. E.g., I have X points in space and want to draw all the lines defined by them - a line being defined by 2 points. So I come up with: def unique2(pointslist): P=[] s=pointslist[:] while len(s): r=s.pop(0) for x in s: P.append([r,x]) return P Or for some number of points > 3, I want to draw all the planes defined by them - a plane being defined by 3 points. So, def unique3(pointslist): P=[] s=pointslist[:] while len(s): r=s.pop(0) t=s[:] while len(t): m=t.pop(0) for x in t: P.append([r,m,x]) return P I haven't been able to come up with a generalization - an alogrithm with a second parameter as the number of elements I want in the returned subset. I am sure these are well-worn issues - but I haven't found the right resource for answers. Anybody have ideas? Art From ajs@ix.netcom.com Sat Mar 2 17:16:05 2002 From: ajs@ix.netcom.com (Arthur Siegel) Date: Sat, 2 Mar 2002 12:16:05 -0500 Subject: [Edu-sig] re: Algorithm help Message-ID: <000901c1c20d$ffffeb90$4ca49840@ArtsPortable> >>by Kirby from May 1991. Meant to say May,2001. Still not bad. From dyoo@hkn.eecs.berkeley.edu Sat Mar 2 21:41:52 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 2 Mar 2002 13:41:52 -0800 (PST) Subject: [Edu-sig] Algorithm help Subsets In-Reply-To: <000001c1c206$3d154140$3354f6d1@ArtsPortable> Message-ID: On Sat, 2 Mar 2002, Arthur Siegel wrote: > I haven't been able to come up with a generalization - an alogrithm with a > second parameter as the number of elements I want in the returned subset. > > I am sure these are well-worn issues - but I haven't found the right > resource for answers. Hi Arthur, We can solve this problem if we look at it recursively. Let's say that unique2() and unique3() are special cases of a generalized subsets() function. This subsets() function should take as arguments the sequence we're choosing from, and the number of elements we'd like for each subset. For example, if we had the sequence: sequence = ['a', 'b', 'c'] then subsets(sequence, 1) should give us: [['a'], ['b'], ['c']] and subsets(sequence, 2) should give us: [['a', 'b'], ['a', 'c'], ['b', 'c']] If we look at our original sequence: ['a', 'b', 'c'] and all its subsets of length 2: [('a', 'b'), ('a', 'c'), ('b', 'c')] we can split the subsets down into two distinct categories: the subsets that contain the first letter 'a': [('a', 'b'), ('a', 'c')] and the ones that don't contain the first letter: [('b', 'c')] The first case turns out to be subsets(['b', 'c'], 1), with a bunch of "a"'s appended to the front of each sub-subset. The second case is subsets(['b', 'c'], 2). When we build those subsets, we can construct those two sub-subset categories, and put them together. As we build them, we have a choice of either including the first element, or not including it. Here is a recursive definition of the subsets function: ### def subsets(sequence, n): """Returns all subsets of length n from the sequence.""" if not sequence or n == 0: return [] if n == 1: return map(lambda x: [x], sequence) case1 = addHeads(sequence[0], subsets(sequence[1:], n-1)) case2 = subsets(sequence[1:], n) return case1 + case2 def addHeads(head, sequence): results = [] for s in sequence: results.append([head] + s) return results ### By the way, Donald Knuth has been writing Volume Four of his "Art of Computer Programming", and he's put up the fascicles for his next two chapters online: http://www-cs-faculty.stanford.edu/~knuth/fasc2a.ps.gz http://www-cs-faculty.stanford.edu/~knuth/fasc2b.ps.gz Lots of good algorithm stuff to look at! *grin* Good luck to you! From dustin@cs.uchicago.edu Sat Mar 2 23:36:13 2002 From: dustin@cs.uchicago.edu (Dustin Mitchell) Date: Sat, 2 Mar 2002 17:36:13 -0600 (CST) Subject: [Edu-sig] COUNTER class. In-Reply-To: <1014830745.7303.103.camel@mdeicaza> Message-ID: On 27 Feb 2002, Jeffrey Elkner wrote: > I couldn't find a way to give this property to assignment. Every time an > assignment happens with one of these things, I would like to count it. > Is there a way to do that? I would guess that assignments you're interested in don't have the form a = 2 * x + 15 but rather have the form array[i] = 2 * x + 15 because scalar variables like 'a' are seldom significant in the analysis of a program, while arrays are. If, then, you attached an "assign" counter to array objects' __setitem__ functions, I think you'd be in business.. Dustin -- Dustin Mitchell dustin@cs.uchicago.edu dustin@ywlcs.org http://people.cs.uchicago.edu/~dustin/ From ajs@ix.netcom.com Sun Mar 3 03:48:36 2002 From: ajs@ix.netcom.com (Arthur Siegel) Date: Sat, 2 Mar 2002 22:48:36 -0500 Subject: [Edu-sig] re: Algorithm help Subsets Message-ID: <000a01c1c266$5983ff00$1b8efea9@ArtsPortable> Danny writes - >>Here is a recursive definition of the subsets function: Thanks. I *almost* understand it - though still having trouble wrapping my head around recursive stuff. Similarly an alogorithm I am using to get the permutations of a list excluding case were list = list.reverse(): def perms(source,done,current=[]): if done == len(source): if current[0] < current[-1]: P.append(current) else: for i in source: if i not in current: perms(source,done+1,current+[i]) I got it from a python-list discussion - but only sort of follow it. Not above using algorithms I don't fully understand. Putting your alogorithm into 'prodiction' with a small amendment: case1 = addHeads(sequence.pop(0), subsets(sequence, n-1)) case2 = subsets(sequence, n) thinking that I am saving 2 slice (sequence[1:]) operations at no cost. Thanks again. Art From Jason Cunliffe" Contagious Fun goes Pro ! Message-ID: <000901c1c299$1138bb40$6401a8c0@jasonic> http://www.profoundeffects.com/article.php?sid=1&mode=thread&order=0&thold=0 http://www.profoundeffects.com/ut.php ./Jason From urnerk@qwest.net Sun Mar 3 15:52:15 2002 From: urnerk@qwest.net (Kirby Urner) Date: Sun, 03 Mar 2002 07:52:15 -0800 Subject: [Edu-sig] re: Algorithm help Subsets In-Reply-To: <000a01c1c266$5983ff00$1b8efea9@ArtsPortable> Message-ID: <4.2.0.58.20020303075013.00cdd4a0@pop3.norton.antivirus> Note: If you want your subsets to be unique, but your inputs aren't, you'd need to make modifications e.g. >>> subsets([2,2,2],2) [[2, 2], [2, 2], [2, 2]] >>> subsets([2,2,1],2) [[2, 2], [2, 1], [2, 1]] This algorithm works best when the input sequence contains unique elements. Kirby From urnerk@qwest.net Sun Mar 3 23:38:09 2002 From: urnerk@qwest.net (Kirby Urner) Date: Sun, 03 Mar 2002 15:38:09 -0800 Subject: [Edu-sig] OnLisp In-Reply-To: Message-ID: <4.2.0.58.20020303153643.00d23c10@pop3.norton.antivirus> At 09:18 AM 3/1/2002 -0800, you wrote: >Thanks for the tip Dethe. I've got the book downloaded and it >looks like a real gem. Ditto. I c'n see why it's outta print -- no mention of Python :-D The ability to pass functions as arguments is cool, and Python has it. No macros though. Wondering what others use for their LISP. I've got Allegro CL Trial (for personal use only) and like it OK (for learning purposes). Kirby From urnerk@qwest.net Mon Mar 11 06:09:13 2002 From: urnerk@qwest.net (Kirby Urner) Date: Sun, 10 Mar 2002 22:09:13 -0800 Subject: [Edu-sig] Python student video In-Reply-To: <1014830745.7303.103.camel@mdeicaza> References: <4.2.0.58.20020224133240.00d08300@pop3.norton.antivirus> <4.2.0.58.20020224133240.00d08300@pop3.norton.antivirus> Message-ID: <4.2.0.58.20020310215943.00d3de40@pop3.norton.antivirus> Hey Jeff -- Thanks to a fast-enough internet connection, I was able to grab and view your school's funky 243 MB mpg video re Python. Great to see you and other members of the cast -- Tim Peters, Guido et al. I'll burn this to a CD and maybe share it with a high schooler or two. Lots of video skills being demoed here too. I like your high tech curriculum. Kirby URL for video and many other interesting presentations at the most recent Python conference: http://www.python.org/workshops/2002-02/ From urnerk@qwest.net Mon Mar 11 18:37:16 2002 From: urnerk@qwest.net (Kirby Urner) Date: Mon, 11 Mar 2002 10:37:16 -0800 Subject: [Edu-sig] RE: [Tutor] Thoughts on little lambda In-Reply-To: References: Message-ID: <4.2.0.58.20020311094139.00cda670@pop3.norton.antivirus> > >Python 2.2's IDLE should resolve the problem. Good luck! 2.2 does make import from __future__ work directly in the IDLE shell (you needn't be in a module), e.g.: >>> from __future__ import division >>> 3/2 1.5 However, in this particular case, using the nested scopes feature, the "fix" comes from not needing to import from __future__ at all, because nested scopes are the default for version 2.2 on. Just to review the construct, I was suggesting a way to make "function factories" (functions that build other functions) which have internal complexity beyond lambda's ability by itself, is to use an internal function called with lambda. E.g. the example below includes a print statement -- something lambda can't, by itself, invoke: >>> def makeadder(n): def main(x): print "Adding %s" % n return x + n return lambda x: main(x) This is the classic case of building an "adder" e.g.: >>> add1 = makeadder(1) >>> add1(5) Adding 1 6 Now it comes up in many applications that you want to do one thing to a number if it's odd, something else if it's even. The template below accepts two *functions* as inputs, and builds a "switcher" with 'em: >>> def evenodd(fe,fo): def main(x): if x%2: # odd return fo(x) else: # even return fe(x) return lambda x: main(x) So, for example, if you'd earlier defined add0 and add1 using the makeadder() function, then here you could pass these to function-builder evenodd() and get a function which adds 0 to evens, 1 to odds: >>> switcher = evenodd(add0,add1) >>> switcher(3) Adding 1 4 >>> switcher(2) Adding 0 2 But note that evenodd(fe,fo) is designed to accept *any* two functions, one to execute if the input is even, the other if odd. I think this provides a good example of "functional programming" in the sense of using functions to build other functions, which in turn involves thinking of functions as the arguments of other functions. But my main focus was to explore ways of overcoming little lambda's inherent limitations, by taking advantage of nested scopes to put the real guts of a function in some internally called construct. The arguments to the builder provide the static content for these guts (variable only at the time the function is built), and then the final lambda return statement handles what will be the dynamic inputs to the built function. In the case of a polynomial builder, you could have a list of coefficients at "build time", then, presuming it's a poly of a single variable (but it doesn't *have* to be) pass "x" in the lambda statement: >>> def buildpoly(coeffs): def main(x): dim = len(coeffs)-1 sum = 0 for c in coeffs: sum += c * pow(x,dim) dim -= 1 return sum return lambda x: main(x) >>> p = buildpoly([2,3,1]) # f(x) = 2x^2 + 3x + 1 >>> p(3) 28 >>> 2*(3**2) + 3*(3) + 1 >>> q = buildpoly([1,2,3,4]) # f(x) = x^3 + 2x^2 + 3x + 4 >>> q(10) 1234 >>> 10**3 + 2*(10**2) + 3*10 + 4 1234 The important thing to note here is buildpoly is returning callable functions, which functions are then applied to specific numbers. Note also that the internally called construct might be recursive. In the example below, recursop(op) wants an operation as input. It builds a recursive function which decrements the argument by 1 each time, stopping when the argument reaches 1 (up to the user here not to pass 1.5 or -1 -- asking for trouble [1]). So if you import mul and add from operator, you can use recursop to build a primitive factorial and and triangular number cruncher. I call it "triangular" because 5+4+3+2+1 may be represented as a triangle: * * * * * * * * * * * * * * * >>> def recursop(op): def main(x): if x==1: return x else: return apply(op,(x,main(x-1))) return lambda x: main(x) >>> factorial = recursop(mul) >>> factorial(5) 120 >>> factorial(7) 5040 >>> 7*6*5*4*3*2 5040 >>> triangular = recursop(add) >>> triangular(10) 55 >>> 10+9+8+7+6+5+4+3+2+1 55 It's a little harder to figure what's going on with recursive subtraction, but it works, if you import sub: >>> something = recursop(sub) >>> something(10) 5 i.e.: >>> 10-(9-(8-(7-(6-(5-(4-(3-(2-1)))))))) 5 These ideas are not new to programmers. It's the kind of stuff you see in Scheme/LISP all the time. I was just wanting to see how Python's little lambda (vs. the big honker lambda of the LISPs) isn't really a major limitation when it comes to writing function-building functions. The new way of doing scoping is what adds power, as the bindings are all local within the builder, and the lambda is charged only with passing what will be the external arguments to the built output functions -- expecting lots of reuse. The builder's calling args, on the other hand, are the one-time definers of the product's behavior. A natural next topic would be to explore this same construct as a way of returning generators, i.e. functions built around the new 'yield' keyword. Kirby [1] because we're using an internal function to provide the guts, more elaborate argument checking, including try/excepts, are certainly doable. From urnerk@qwest.net Mon Mar 11 18:58:30 2002 From: urnerk@qwest.net (Kirby Urner) Date: Mon, 11 Mar 2002 10:58:30 -0800 Subject: [Edu-sig] Re: [Tutor] Thoughts on little lambda In-Reply-To: <3C8CF8F4.C4009ADD@ccvcorp.com> References: Message-ID: <4.2.0.58.20020311104645.01b5ed30@pop3.norton.antivirus> You make an excellent point Jeff. It wasn't clear to me at first that I was moving towards such a simple lambda, so simple, in fact, that we don't need it at all. So the template should be revised as you've indicated: def builder(B_arg1,B_arg2...): def main(E_args): # statements using B_arg1,B_arg2 return main # expecting E_args as inputs So take all of my earlier templates and make this change of 'return lambda x: main(x)' --> 'return main' Thanks for the insight! Next question: Is there a way to associate a customized doc string with the built function? Kirby >Recently, Kirby Urner described a bit about the differences between >Python's lambda and Lisp-ish >lambdas. To create something that works a bit more like the Lisp-ish >lambda, Kirby proposed using a >function factory like this: > > > > def funcfact(r,j): > > def main(x): > > if not x%2: > > return pow(x,j)+4 > > else: > > return pow(x,r)+3 > > return lambda x: main(x) > >Now, I might be missing something (wouldn't be the first time ;) ) but it >seems to me that the return >statement doesn't need to create a lambda; it should be equivalent to >change it to simply > > return main > >shouldn't it? ISTM that the lambda here creates a function object that >calls a function, using >exactly the arguments passed to it; I see no benefit to encapsulating >that second function object >(the main in the above example) inside of another function object (and >some cost in terms of >overhead). > >Jeff Shannon >Technician/Programmer >Credit International From jeff@ccvcorp.com Mon Mar 11 19:20:25 2002 From: jeff@ccvcorp.com (Jeff Shannon) Date: Mon, 11 Mar 2002 11:20:25 -0800 Subject: [Edu-sig] Re: [Tutor] Thoughts on little lambda References: <4.2.0.58.20020311104645.01b5ed30@pop3.norton.antivirus> Message-ID: <3C8D0379.D37C2C40@ccvcorp.com> Kirby Urner wrote: > > Next question: Is there a way to associate a customized > doc string with the built function? A brief experiment in the interpreter seems to indicate that a function's __doc__ is assignable, so it should be possible, after defining the function but before returning it, to do main.__doc__ = "This function returns %s" % descripton or something similar. Jeff Shannon Technician/Programmer Credit International From dyoo@hkn.eecs.berkeley.edu Mon Mar 11 20:11:03 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 11 Mar 2002 12:11:03 -0800 (PST) Subject: [Edu-sig] Re: [Tutor] Thoughts on little lambda In-Reply-To: <3C8D0379.D37C2C40@ccvcorp.com> Message-ID: On Mon, 11 Mar 2002, Jeff Shannon wrote: > > > Kirby Urner wrote: > > > > > Next question: Is there a way to associate a customized > > doc string with the built function? > > A brief experiment in the interpreter seems to indicate that a function's > __doc__ is assignable, so it should be possible, after defining the function > but before returning it, to do > > main.__doc__ = "This function returns %s" % descripton > > or something similar. Here's a concrete example of this: ### >>> def makeAdder(n): ... def function(x): ... "This function adds %(n)s to x." ... return n + x ... function.__doc__ = function.__doc__ % {'n' : n} ... return function ... >>> f = makeAdder(42) >>> f.__doc__ 'This function adds 42 to x.' ### From urnerk@qwest.net Mon Mar 11 22:07:37 2002 From: urnerk@qwest.net (Kirby Urner) Date: Mon, 11 Mar 2002 14:07:37 -0800 Subject: [Edu-sig] Re: [Tutor] Thoughts on little lambda In-Reply-To: References: <3C8D0379.D37C2C40@ccvcorp.com> Message-ID: <4.2.0.58.20020311140531.00cd8a20@pop3.norton.antivirus> At 12:11 PM 3/11/2002 -0800, Danny Yoo wrote: > > A brief experiment in the interpreter seems to indicate that a > > function's __doc__ is assignable, so it should be possible, after > > defining the function but before returning it, to do > > > > main.__doc__ = "This function returns %s" % descripton > > > > or something similar. > > >Here's a concrete example of this: > >### > >>> def makeAdder(n): >... def function(x): >... "This function adds %(n)s to x." >... return n + x >... function.__doc__ = function.__doc__ % {'n' : n} >... return function >... > >>> f = makeAdder(42) > >>> f.__doc__ >'This function adds 42 to x.' >### > Or even just: >>> def makeAdder(n): def function(x): return n + x function.__doc__ = "This function adds %s to x." % n return function >>> add42 = makeAdder(42) >>> help(add42) Help on function function: function(x) This function adds 1 to x. Kirby From Burley, Brent" Kirby wrote: > Just to review the construct, I was suggesting a way to > make "function factories" (functions that build other > functions) which have internal complexity beyond lambda's > ability by itself, is to use an internal function called > with lambda. > > E.g. the example below includes a print statement -- > something lambda can't, by itself, invoke: > > >>> def makeadder(n): > def main(x): > print "Adding %s" % n > return x + n > return main In "functional language" language, binding a function with a partial argument list is called "currying". Here's a nice description: http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?curried+function Here's the same thing, but in an explicitly curried form: def adder(x, n): print "Adding %s" % n return x + n def makeadder(n): return lambda x: adder(x, n) The main difference is that it wraps the adder function rather than redefining it each time. There's also a recipe for a general currying class here: http://aspn.ActiveState.com/ASPN/Cookbook/Python/Recipe/52549 You use it directly like this: add2 = curry(adder, 2) The curry class supports currying of arbitrary arguments (including keyword args!) and has the added benefit that it doesn't require nested scopes and thus works on older versions of python. Brent From urnerk@qwest.net Tue Mar 12 19:57:39 2002 From: urnerk@qwest.net (Kirby Urner) Date: Tue, 12 Mar 2002 11:57:39 -0800 Subject: [Edu-sig] Re: [Tutor] Thoughts on little lambda In-Reply-To: <3C8E5A22.A7696546@fa.disney.com> Message-ID: <4.2.0.58.20020312115613.00d25100@pop3.norton.antivirus> > >There's also a recipe for a general currying class here: >http://aspn.ActiveState.com/ASPN/Cookbook/Python/Recipe/52549 >You use it directly like this: > add2 = curry(adder, 2) Thanks for the background and pointer. I see the above gives some examples using nested scopes as well. Good stuff. Kirby From arthur.siegel@rsmi.com Thu Mar 14 14:27:24 2002 From: arthur.siegel@rsmi.com (arthur.siegel@rsmi.com) Date: Thu, 14 Mar 2002 09:27:24 -0500 Subject: [Edu-sig] random appreciation Message-ID: So the next phase of my Python powered efforts at personal math re-education is to get some decent handle on complex math - with, as usual, a prejudice toward a visual approach. The perfect book to get me there being Visual Complex Analysis by Tristan Needham. So I am in the introduction and realize I have my hands full in trying to follow along. Want to create a Python class to help. Struggling until I remember the new ability to sub-class builtins. from cmath import * from __future__ import division class Complex(complex): def __init__(self,real,imag): complex.__init__(real,imag) def arg(self): return asin(self.imag/self.real) def polar(self): return e**complex(0,self.arg()) def mod(self): return sqrt(self.real**2+self.imag**2) Have no confidence yet that even that little ditty is constructed and returning correctly. Have great confidence that I am privileged to have access to tools that will make this kind of effort realistic for myself. And yes, it *is* nice not to have to worry about where self.imag/self.real might leave me. Art From sandysj@asme.org Thu Mar 14 23:54:31 2002 From: sandysj@asme.org (Jeff Sandys) Date: Thu, 14 Mar 2002 15:54:31 -0800 (PST) Subject: [Edu-sig] Why colon? Message-ID: <20020314235431.35114.qmail@web12801.mail.yahoo.com> What is the use of the colon in def and if? It only seems to signal, indent the next line, but if the next line is indented anyway, what is the colon's purpose? We have a semi-colon to put multiple statements on a line, why not use that for a single-line if, if x > 0 ; print "positive" else ; print "negative" Then when we use multiple lines we still indent, if x > 0 print "positive" else print "negative" It is a common error of new Python programmers to leave out the colon after def, if and else, and I can't explain why the colon is needed. Thanks, Jeff Sandys __________________________________________________ Do You Yahoo!? Yahoo! Sports - live college hoops coverage http://sports.yahoo.com/ From urnerk@qwest.net Fri Mar 15 07:12:27 2002 From: urnerk@qwest.net (Kirby Urner) Date: Thu, 14 Mar 2002 23:12:27 -0800 Subject: [Edu-sig] Fun geometry w/ Python's help Message-ID: <4.2.0.58.20020314225220.00ce9a50@pop3.norton.antivirus> Greetings all -- Just thought I'd share results of a project with other Pythonistas. Here's a POV-Ray graphic [1] I generated earlier today using Python to write the script: http://www.inetarena.com/~pdx4d/ocn/graphics/w1000.gif What we're seeing are balls in a cubic close packing (ccp) out to distance sqrt(1000) from the origin. Color coding indicates different distances, with orange balls being at maximum distance.[3] Source code is here: http://www.inetarena.com/~pdx4d/ocn/python/ccp.py Note I'm also importing modules coords.py (a vector implementation) and povray.py (used to write vectors in coords to POV-Ray). Both are available at same URL.[2] Kirby [1] Re POV-Ray: http://www.povray.org [2] related info and more graphics at: http://www.inetarena.com/~pdx4d/ocn/wgraphics.html [3] background on povray.py and coords.py is at http://www.inetarena.com/~pdx4d/ocn/numeracy0.html ff From guido@python.org Fri Mar 15 17:11:52 2002 From: guido@python.org (Guido van Rossum) Date: Fri, 15 Mar 2002 12:11:52 -0500 Subject: [Edu-sig] Why colon? Message-ID: <200203151711.g2FHBqX03495@pcp742651pcs.reston01.va.comcast.net> > What is the use of the colon in def and if? > It only seems to signal, indent the next line, > but if the next line is indented anyway, > what is the colon's purpose? > > We have a semi-colon to put multiple statements > on a line, why not use that for a single-line if, > > if x > 0 ; print "positive" > else ; print "negative" > > Then when we use multiple lines we still indent, > > if x > 0 > print "positive" > else > print "negative" > > It is a common error of new Python programmers > to leave out the colon after def, if and else, > and I can't explain why the colon is needed. > > Thanks, > Jeff Sandys This is a FAQ (but anyway, it's too late to change): http://www.python.org/cgi-bin/faqw.py?query=colon&querytype=simple&casefold=yes&req=search The colon is required primarily to enhance readability (one of the results of the expirimental ABC language). Consider this: if a==b print a versus if a==b: print a Notice how the second one is slightly easier to read. Notice further how a colon sets off the example in the second line of this FAQ answer; it's a standard usage in English. Finally, the colon makes it easier for editors with syntax highlighting. --Guido van Rossum (home page: http://www.python.org/~guido/) From ajs@ix.netcom.com Fri Mar 15 17:53:34 2002 From: ajs@ix.netcom.com (Arthur) Date: Fri, 15 Mar 2002 12:53:34 -0500 Subject: [Edu-sig] re: random appreciation Message-ID: I had wrttien: >And yes, it *is* nice not to have to worry about where >self.imag/self.real might leave me. Except of course for the fact the formula is dead wrong, and oh yeah divide by zero, and.... details, details... Meanwhile studying Guido's Type/class unification paper at www.python.org/2.2/descrintro.html I'll get there. Art ------------------------------------------------------- From rkr_ii@yahoo.com Fri Mar 15 18:47:58 2002 From: rkr_ii@yahoo.com (Robert Rickenbrode) Date: Fri, 15 Mar 2002 10:47:58 -0800 (PST) Subject: [Edu-sig] tkinter Canvas Object Pixel Values Message-ID: <20020315184758.45838.qmail@web13406.mail.yahoo.com> Hey folks; does anyone know if it's possible to find the color of a particular pixel for a tkinter canvas object? If so, how? Thanks, Rob __________________________________________________ Do You Yahoo!? Yahoo! Sports - live college hoops coverage http://sports.yahoo.com/ From goodmansond@yahoo.com Fri Mar 15 18:59:05 2002 From: goodmansond@yahoo.com (Dean Goodmanson) Date: Fri, 15 Mar 2002 10:59:05 -0800 (PST) Subject: [Edu-sig] RE: Why Colon? Message-ID: <20020315185905.57893.qmail@web21104.mail.yahoo.com> This is a recuring question on comp.lang.py, here's one of the larger threads. http://groups.google.com/groups?hl=en&ie=ISO-8859-1&oe=ISO-8859-1&threadm=3c4c5f6f.1987456212%40news&rnum=11&prev=/groups%3Fq%3Dcolon%2Bgroup:comp.lang.python.*%26start%3D10%26hl%3Den%26ie%3DISO-8859-1%26oe%3DISO-8859-1%26selm%3D3c4c5f6f.1987456212%2540news%26rnum%3D11 Sorry, I've run out of lunchtime break to post a summary. :( Tim Peter's summary may help: http://groups.google.com/groups?hl=en&ie=ISO-8859-1&oe=ISO-8859-1&frame=right&rnum=51&thl=1118048253,1117994867,1117957848,1117593072,1116658121,1118226724,1118170447,1117903809,1117884472,1117029114,1116566848,1116546163&seekm=slrna4ltp5.9m5.grante%40tuxtop.visi.com#link56 __________________________________________________ Do You Yahoo!? Yahoo! Sports - live college hoops coverage http://sports.yahoo.com/ From dyoo@hkn.eecs.berkeley.edu Fri Mar 15 21:44:42 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 15 Mar 2002 13:44:42 -0800 (PST) Subject: [Edu-sig] Re: [Tutor] Fun geometry w/ Python's help [geometry and PyMol?] In-Reply-To: <4.2.0.58.20020314225220.00ce9a50@pop3.norton.antivirus> Message-ID: On Thu, 14 Mar 2002, Kirby Urner wrote: > Here's a POV-Ray graphic [1] I generated earlier today > using Python to write the script: > > http://www.inetarena.com/~pdx4d/ocn/graphics/w1000.gif > > What we're seeing are balls in a cubic close packing (ccp) > out to distance sqrt(1000) from the origin. Color coding > indicates different distances, with orange balls being > at maximum distance.[3] Hi Kirby, This is very cool! By the way, during the recent BayPiggies meeting two days ago, I got my first glance at PyMol: http://pymol.sourceforge.net/ This program allows one to build molecular models in real time. I was stunned to see how the program would allow me to pull and tug on the atoms, and have the whole structure warp and stretch. Tinker toys on a mass scale. I felt like a little kid again. *grin* Perhaps there might be something in PyMol that could be useful for the geometrical programs that you've been working on. Good luck to you. From ajs@ix.netcom.com Tue Mar 19 13:36:21 2002 From: ajs@ix.netcom.com (Arthur Siegel) Date: Tue, 19 Mar 2002 08:36:21 -0500 Subject: [Edu-sig] The right learning environment Message-ID: <000701c1cf4b$0eff6540$0334fea9@carol> I will be guilty of selectively presenting evidence that supports my intuition/position/experience on learning environments. The book "Beginning ASP.NET using C#" (Wrox) considers its audience: "You're a beginner to programming and you've chosen ASP.NET as the technology with which to get started." The recommended coding environment: "We strongly suggest (and will assume throughout) that you use Notepad to code all examples in this book, since it will always do precisely what you ask it to and no more." In my opinion, and from my experience, they are suggesting something wise. Not taking gratuitous pot-shots at others efforts - it is a simple fact that before I came to Python I had downloaded and tried to get started with Dr. Scheme. The fact that I could not (remember I'm a rank beginner) understand what role the environment was playing - the fact that it was all seemed quite opaque - was something I could not get past. It was counter to the reasons I was motivated to try to learn programming in the first place. Full transparency was a requirement, at least for myself. I ended up with Python and a little more fancy Notepad - a Windows shareware text editor. *No* learning environment is the best learning environment. Which I would only modify to the extent that I would say that the Python interactive prompt brings transparency to a new level - and is very much something that can and should be taken advantage of for learning. Not sure anyone is interested in reviving meta-discussions and past hysterias. But the truth is that I have sometimes felt marginalized here by pressing what I think is a quite reasonable and defensible point of view. So I do feel a bit compelled to throw something like this up when I come across it. Art From urnerk@qwest.net Tue Mar 19 15:44:50 2002 From: urnerk@qwest.net (Kirby Urner) Date: Tue, 19 Mar 2002 07:44:50 -0800 Subject: [Edu-sig] The right learning environment In-Reply-To: <000701c1cf4b$0eff6540$0334fea9@carol> Message-ID: <4.2.0.58.20020319073724.019fe230@pop3.norton.antivirus> > >Not sure anyone is interested in reviving meta-discussions and >past hysterias. But the truth is that I have sometimes felt >marginalized here by pressing what I think is a quite reasonable >and defensible point of view. So I do feel a bit compelled to >throw something like this up when I come across it. > >Art I have nothing against notepad to start if that's what a user is already comfortable with, but would hope a user would outgrow it quickly, and that freeware assets could soon provide at least color coding. Being able to highlight open-close parentheses is less necessary in Python than Scheme or some other languages, but is still a nice feature. The ability to indent whole blocks at once is more relevant. If the language offers a shell, one should also use the shell, without even a text editor. Entering 1+1 to get 2 is even more basic than 'Hello World'. The command line just sits there, waiting to give immediate feedback. Some people don't discover this about Python until late in the game, and I think that's a pity. I like that Guido's tutorial starts with 'using Python as a calculator'. Seems to me the text editor in IDLE is no less intuitive than Notepad, once one realizes its function. I can understand a newbie being confused about what it does and what it's for. But that's where a good tutorial comes in. These things should simply be explained. Kirby From matthias@ccs.neu.edu Tue Mar 19 18:40:48 2002 From: matthias@ccs.neu.edu (Matthias Felleisen) Date: Tue, 19 Mar 2002 13:40:48 -0500 (EST) Subject: [Edu-sig] Re: The right learning environment In-Reply-To: (edu-sig-request@python.org) References: Message-ID: <20020319184048.1E047206F6@sualocin.ccs.neu.edu> If the language offers a shell, one should also use the shell, without even a text editor. Entering 1+1 to get 2 is even more basic than 'Hello World'. The command line just sits there, waiting to give immediate feedback. Some people don't discover this about Python until late in the game, and I think that's a pity. I like that Guido's tutorial starts with 'using Python as a calculator'. And how exactly does DrScheme differ? -- Matthias From Jason Cunliffe" Message-ID: <005301c1cf79$ddfb2220$6401a8c0@vaio> Greetings > Seems to me the text editor in IDLE is no less intuitive > than Notepad, once one realizes its function. I can > understand a newbie being confused about what it does and > what it's for. But that's where a good tutorial comes in. > These things should simply be explained. Yes Lesson #1 should maybe have a clear sidebar article which walks users through the basic idea: 1. You can use ANY text editor such as Notepad to write or read a file. 2. Launch Python 3. Open text editor and write a script .SAVE [see below about path/import issues] 4. In Python import and run your new script 5. make changes in external text editor 6. Now same again but this time but using Python's own text editor 7. quick summary of pros/cons of both approaches I consider I have good 'beginner' credentials.. Nothing wrong with using Notepad. Its real advantage I feel is to help one rapidly appreciate what is better. I use variously, IDLE, PythonWin shell [Scintilla], and these days UltraEdit32. What's confusing to beginners? Here's my Python A-list - The !@#$ path [where is set, how to change it, how to add to it] - Where to save your own files. Imagine your write first file "hello.py" perhaps using Notepad You save it into a nice new folder called "studytests". Now import "hello.py"... oops! OK import hello ... oops!arggh!! Why does Python not find my folder? How can I tell Python to find my folder? How can I tell python to remember NEXT TIME where my hello.py is? Why do I have to type keep long path/file names? What is the equivalent of CD command ? Why are not standard navigation commands included as default [cd, ls, pwd, dir, list.. the usual suspects]. Python is __always__ used in an environment [OS], users should have at least the same basic access to file+system navigation that those environments have. It makes zero sense to exclude them especially in CLI tool. [Yes I know there are some commands, but try to find them.. jeezus what does have to be so obscure??] - How to move python files and folders around on your computer and still have them work. It relates to the point above. Don't underestimate the importance of this. This is the most mysterious and common problems people have with computers, whether shell or GUI interfaces. Just watch an *nix user [including very experienced ones] and see how much time they spend repeatedly searching and linking files. I would guess that 75% of problems of all users on all OS derive from problems of poor navigation or misdirected paths and links. Establishing basic literacy and skills for this are essential for any real world success on computers. - How do you FIND something in python? Where is the find command and how do I use it? - Trying to work in a DOS shell [no history, awful cut'n'paste, no completion or prompts] - Trying to run python in DOS shell and import a "hello.py" file [You think this is easy? - go find a 100% total newbie and watch them..] - Where Python is located and what the difference is between typing python in say a DOS command shell, python.exe, and what's what in the Python installation folder ? python.exe, pythonw.exe, IDLE.. Please somebody draw a little map/table for beginners who do want to know where important things are, what the differences are, when to use them etc. - Having to type "" and , so much [they really often seem so unnecessary - but that's a olde language war topic. It is a basic question beginners keep until they have their common sense dogmatically beaten out of them and 'learn' why this is correct and necessary] - The difference between TAB and 4/8 spaces in Python, [and what to do about that in any edit tool you use]. Within IDLE, PythonWin what about nicer ways to visualize the indentation issues. - NAMESPACE - How to import and use modules you download from the Internet [where to save them, how to load them, import and import from..] -------- What's cool about Python [IDLE PythonWin] for beginners? - CLI - indentation - color syntax - completion - execution - free - cross-platform - library of contributed modules [but how to use them??] ./Jason From ajs@ix.netcom.com Wed Mar 20 01:26:12 2002 From: ajs@ix.netcom.com (Arthur Siegel) Date: Tue, 19 Mar 2002 20:26:12 -0500 Subject: [Edu-sig] Re: The right learning environment Message-ID: <000701c1cfae$395deb00$0334fea9@carol> Eeks. Forgot Mathias was here. > If the language offers a shell, one should also use the shell, > without even a text editor. Entering 1+1 to get 2 is even more > basic than 'Hello World'. The command line just sits there, > waiting to give immediate feedback. Some people don't discover > this about Python until late in the game, and I think that's a > pity. I like that Guido's tutorial starts with 'using Python > as a calculator'. Yup. Kind of neat that I don't need to abstract about this, "Worked for me" covers it. >And how exactly does DrScheme differ? -- Matthias The short answer is I don't know, and you would know much better than I. The longer answer is that I - so we have as cross-section of one - experience it very differently. I was in an environment, created by folks who thought they might have a beat on how I learned, but probably didn't. I happen to learn sloppy, not neat. Three measures of "start from the beginning ", and a measure of "let me skip over to that for a bit" and a measure of "what would happen if I tried that" and a few measures of "now that I get that, let's start back from the beginning again and see if I understand some of what I missed the first time around", and a measure of "let's see what happens in Chapter Six, just to get a taste of what's to come", a measure of "you know I don't *really* even understand what 'pi' is, so let's get that straight before I do much else", and a measure of "oh yeah were we programming, shucks got to start at the beginning again". But damn it I do learn. Not sure an environment or lesson plans can handle that. Though if I thought I really was unusual in any real way, I wouldn't expect anyone to be interested. But it does explain why the Open Source movement and the internet have changed the intellectual lives of folks like myself. Make the tools and information we might use available, a push to get us started is well appreciated, (keep some tabs on us if you must - I understand a teacher does have a responsibility to do that) and us sloppy learners will take it from there - each in our own sloppy way. *If*, of course it happens that the time is right - i.e. we *want* to learn. Because if we don't, none of this is very interesting for anybody. The fact is that DrScheme was - I am willing to bet - the best pre-Internet alternative there was. But now any environment that is in any way isolating - and yes Mathias it's an opinion/experience that DrScheme is (somewhat) - is no longer optimum. The Internet is the ultimate learning environment. Students find a text editor you are comfortable with. There are plenty to choose from. I happen to recommend X, Y, or Z. but the important thing to know is that it doesn't really matter that much which you choose. We got bigger fish to fry. Art From urnerk@qwest.net Wed Mar 20 15:30:53 2002 From: urnerk@qwest.net (Kirby Urner) Date: Wed, 20 Mar 2002 07:30:53 -0800 Subject: [Edu-sig] Re: The right learning environment In-Reply-To: <20020319184048.1E047206F6@sualocin.ccs.neu.edu> References: Message-ID: <4.2.0.58.20020320072720.015bfdc0@pop3.norton.antivirus> At 01:40 PM 3/19/2002 -0500, Matthias Felleisen wrote: > If the language offers a shell, one should also use the shell, > without even a text editor. Entering 1+1 to get 2 is even more > basic than 'Hello World'. The command line just sits there, > waiting to give immediate feedback. Some people don't discover > this about Python until late in the game, and I think that's a > pity. I like that Guido's tutorial starts with 'using Python > as a calculator'. > >And how exactly does DrScheme differ? -- Matthias DrScheme does not differ at all in this respect. > (+ 1 1) 2 is isomorphic to Python's >>> 1 + 1 2 DrScheme and Python both have shell environments and this is where to start with newbies IMO, engaging in simple calculator-style dialog in order to learn the grammar of the language (either one). Writing chunks of code, then saving these chunks for later retrieval, would be subsequent steps (in either environment). Kirby From urnerk@qwest.net Wed Mar 20 15:39:39 2002 From: urnerk@qwest.net (Kirby Urner) Date: Wed, 20 Mar 2002 07:39:39 -0800 Subject: [Edu-sig] Re: The right learning environment In-Reply-To: <000701c1cfae$395deb00$0334fea9@carol> Message-ID: <4.2.0.58.20020320073315.015caba0@pop3.norton.antivirus> At 08:26 PM 3/19/2002 -0500, Arthur Siegel wrote: >But it does explain why the Open Source movement and >the internet have changed the intellectual lives of folks >like myself. Notepad, however, is a proprietary text editor on a non-open-source OS. >The fact is that DrScheme was - I am willing to bet - >the best pre-Internet alternative there was. But now >any environment that is in any way isolating - and >yes Mathias it's an opinion/experience that DrScheme >is (somewhat) - is no longer optimum. > >The Internet is the ultimate learning environment. DrScheme has rich on-line teaching resources. The language itself is able to negotiate on-line protocols such as http, although the tutorials don't focus on this so much. Given Scheme is as capable in principle of doing CGI type stuff and Python or Perl, it'd make sense to have more demos and examples of this in the Scheme syllabi (both on-line and book form), likewise XML parsing. Many times, this is where students are focussed, on web server issues. >Students find a text editor you are comfortable with. >There are plenty to choose from. I happen to >recommend X, Y, or Z. but the important thing to know >is that it doesn't really matter that much which you choose. This is true of both Python and DrScheme -- any text editor will do, but some are more "program editors" than text editors (like Vi and Emacs) meaning they're syntax aware. Kirby From urnerk@qwest.net Wed Mar 20 16:19:13 2002 From: urnerk@qwest.net (Kirby Urner) Date: Wed, 20 Mar 2002 08:19:13 -0800 Subject: [Edu-sig] Re: The right learning environment In-Reply-To: <4.2.0.58.20020320073315.015caba0@pop3.norton.antivirus> References: <000701c1cfae$395deb00$0334fea9@carol> Message-ID: <4.2.0.58.20020320080500.015c2520@pop3.norton.antivirus> > >this so much. Given Scheme is as capable in principle >of doing CGI type stuff and Python or Perl, it'd make ^^^ meant: ala i.e. in a similar vein, same way as, in an equivalent mode As per your non-linear approach, Arthur, I think your tendency to jump ahead (to "chapter 6") and preview is good, and worth building in to a curriculum. Students want to see where this is all leading, i.e. what will I be able to do after I finish this course of study? To this end, I like tackling a language at more than one level, i.e. just building up from primitives, and expecting to build an HTML parser from scratch, takes too long and is too daunting for a beginner. Better is to do *some* building up from primitives, but mixed with accessing already-written advanced library features, and just learning the API. This is characteristic of real world programming; you don't reinvent the wheel every time you need one. Taking advantage of library features gives you access to some of the powerful stuff you want to do, while building up from scratch gives you a sense of how these library utilities are written -- and as you advance in your studies, you'll become more able to read what's in the library (if it's in a language you know -- Python modules might be written in something else). Like one of the student programmers mentioned in that Python video made by students at Yorktown High (where Jeff Elkner teaches -- one of the talking heads), the kind of questions he gets from Python beginners are often about CGI kinds of things, whereas in C++ classes, the questions never got to this level, as students never progressed that far. Kirby From arthur.siegel@rsmi.com Wed Mar 20 17:14:37 2002 From: arthur.siegel@rsmi.com (arthur.siegel@rsmi.com) Date: Wed, 20 Mar 2002 12:14:37 -0500 Subject: [Edu-sig] Re: The right learning environment Message-ID: >Notepad, however, is a proprietary text editor on a >non-open-source OS. OS is not a *religious* thing with me. In my case I was more than happy to pay the $20 (at the time) shareware fee for Textpad - a Windows based, closed source, editor which was configurable enough for me - easy to add Python (and PyGeo for that matter) syntax highlighting, easy to have the interpreter called with or without arguments That being said - I am making some conscious effort to do more on Linux and hope to be able to make it my default working environment. And that more out of principle than convenience. >DrScheme has rich on-line teaching resources. The >language itself is able to negotiate on-line protocols >such as http, although the tutorials don't focus on >this so much. Given Scheme is as capable in principle >of doing CGI type stuff and Python or Perl, it'd make >sense to have more demos and examples of this in the >Scheme syllabi (both on-line and book form), likewise >XML parsing. Many times, this is where students are >focussed, on web server issues. Not looking to knock DrScheme. But my experience was my experience. And hopefully I am not doing any harm by reporting my experience to Mathias. I have never experienced DrScheme in the context of a formal curriculum. And since that is how it is intended to be used, Mathias should not be shocked that perhaps it does not work quite as well outside of that kind of setting. >This is true of both Python and DrScheme -- any text >editor will do, but some are more "program editors" than >text editors (like Vi and Emacs) meaning they're syntax >aware. If that is true of DrScheme it is very, very hard to understand it from inside it. I understand (now) that it is true of the Scheme implementation underlying DrScheme - but DrScheme itself did not get across to me that there was a way to run things from outside of itself. And I am hoping it never gets to the point where folks may run into the same kind of confusion (because you are probably right - I was confused) about IDLE - though I don't now see anything to indicate that things are on a trajectory where that is a real concern. Art From sandysj@asme.org Wed Mar 20 22:28:07 2002 From: sandysj@asme.org (Jeff Sandys) Date: Wed, 20 Mar 2002 14:28:07 -0800 (PST) Subject: [Edu-sig] Re: The right learning environment In-Reply-To: Message-ID: <20020320222807.26604.qmail@web12801.mail.yahoo.com> Kirby said: > DrScheme and Python both have shell environments and this is > where to start with newbies IMO, engaging in simple > calculator-style dialog in order to learn the grammar > of the language (either one). ... > DrScheme has rich on-line teaching resources. Is this missing from Python UI (IDLE, PythonWin, PyCrust)? Couldn't these User Interfaces have an addition window for a lesson or other resource to appear? ---------------------- Jason said: > What's confusing to beginners? Here's my Python A-list ... I agree that many of these path issues are hard to figure, (I still can't get Piddle and PIL configured to work, if someone could only draw me a directory map...) It is the one thing that scares me away from teaching Python (on another platform, no less) to younger students, is fumbling around trying to solve a path problem while the student is thinking, if the instructor can't solve it how am I going to learn this. Thanks, Jeff Sandys __________________________________________________ Do You Yahoo!? Yahoo! Movies - coverage of the 74th Academy Awards® http://movies.yahoo.com/ From pobrien@orbtech.com Wed Mar 20 22:43:48 2002 From: pobrien@orbtech.com (Patrick K. O'Brien) Date: Wed, 20 Mar 2002 16:43:48 -0600 Subject: [Edu-sig] Re: The right learning environment In-Reply-To: <20020320222807.26604.qmail@web12801.mail.yahoo.com> Message-ID: [Jeff Sandys] > > DrScheme has rich on-line teaching resources. > > Is this missing from Python UI (IDLE, PythonWin, PyCrust)? > Couldn't these User Interfaces have an addition window > for a lesson or other resource to appear? 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. All the foundation work is done. The PyCrust shell can be manipulated like any other Python object. All that's missing is someone with a little imagination that wanted to run with this. --- Patrick K. O'Brien Orbtech From ajs@ix.netcom.com Thu Mar 21 03:30:36 2002 From: ajs@ix.netcom.com (Arthur Siegel) Date: Wed, 20 Mar 2002 22:30:36 -0500 Subject: [Edu-sig] Re: The right learning environment Message-ID: <000601c1d088$d99d9f40$0334fea9@carol> Jeff writes - >Is this missing from Python UI (IDLE, PythonWin, PyCrust)? >Couldn't these User Interfaces have an addition window >for a lesson or other resource to appear? One man's bug is another man's feature. Can I ask you why it is important that the lesson appear as a window of the user interface? Would an html page in a browser work - that approach having become more or less the standard way of supplementing a GUI with help or any other text and graphic based supplementary material? What of course is much more interesting and important is what the *content* of those lessons will be - whether they pop out of the GUI window or exist in a separate web page. I plead absolutely guilty of having helped get edu-sig off on another discussion of form at the expense of content - ironically having done so in trying to make the point that perhaps the interface is not at all that important, There seems to be some prevailing sentiment otherwise. I will respectfully disagree, and go silent on the issue. But would love to join any discussion of curriculum content - about which I of course also have a host of opinions (along with a decent amount of code). Sad and ironic that the most satisfying discussions I have had about Python and education have been conducted outside the Python community - mostly with me as an advocate, and - from all I can ell - seeming to be making perfect sense to people. Impressive people. And here I never get a sense of making sense at all. Yes, I find it frustrating. Art From ajs@ix.netcom.com Thu Mar 21 14:09:27 2002 From: ajs@ix.netcom.com (Arthur Siegel) Date: Thu, 21 Mar 2002 09:09:27 -0500 Subject: [Edu-sig] Re: The right learning environment Message-ID: <000b01c1d0e2$03edffc0$0334fea9@carol> >As per your non-linear approach, Arthur, I think your >tendency to jump ahead (to "chapter 6") and preview is >good, and worth building in to a curriculum. Students >want to see where this is all leading, i.e. what will >I be able to do after I finish this course of study? Along as you try to keep in mind that calling it an "approach" in my case is probably giving it too much credit. It's an "is". Happens to be the *only* way I can effectively learn. All I am advocating is a curriculum that accounts for/ allows as legitimate this style of learning, among others. Crap. I think I'm sounding like a Piaget-ite. The devil of course as always being in the details. Art From urnerk@qwest.net Thu Mar 21 16:08:13 2002 From: urnerk@qwest.net (Kirby Urner) Date: Thu, 21 Mar 2002 08:08:13 -0800 Subject: [Edu-sig] Re: The right learning environment In-Reply-To: <000601c1d088$d99d9f40$0334fea9@carol> Message-ID: <4.2.0.58.20020321075815.00ad6520@pop3.norton.antivirus> At 10:30 PM 3/20/2002 -0500, Arthur wrote: >Sad and ironic that the most satisfying discussions I have >had about Python and education have been conducted outside >the Python community - mostly with me as an advocate, and - >from all I can tell - seeming to be making perfect sense >to people. Impressive people. I don't find that sad. It's good news. Here and elsewhere among Pythonistas, I think you'll find little argument re Python's suitability as a teaching language. Only preaching to the choir is what'd be sad. As for the specifics of pedagogy, that varies with the audience (past experience important) and the teacher (ditto). >And here I never get a sense of making sense at all. Yeah, I couldn't understand how pushing Notepad made any sense -- a sucky little program :-D. But now I think you just meant "any ol' text editor" -- you were advocating unbundling Python from any specific IDE. I don't have a huge problem with that -- I just think newbies should know what's available, starting with IDLE simply because it installs with the product (unless you skip the Tk install). Because Python doesn't have a native GUI, but is designed to piggy back on other GUI-builder languages which export an API, it makes some sense to have a GUI text editor for programming in which Python itself has a glue language role -- makes the shell and/or editor you're using be a demonstration of Python's abilities. IDLE fits this bill as well (but so do other IDEs). PyCrust is certainly a useful tool -- last I checked, it was a shell, w/o a text editor, and this would promote the kind of unbundled approach you're advocating. And as long as the shell is in the picture (and I prefer GUI-based, but it's not mandatory), I think we're doing Python justice. What I don't like are teaching approaches heavily influenced by C or Java which pretend you can only write scripts/programs, and don't explore the interactive potential of a command line environment. Yet the latter is a wonderfuls scratch pad in which to test/learn the basics of the language, with immediate feedback. To bypass the shell is to make a huge pedagogical error, IMO. Kirby >Yes, I find it frustrating. > >Art > > > > > > > >_______________________________________________ >Edu-sig mailing list >Edu-sig@python.org >http://mail.python.org/mailman/listinfo/edu-sig From pobrien@orbtech.com Thu Mar 21 16:42:23 2002 From: pobrien@orbtech.com (Patrick K. O'Brien) Date: Thu, 21 Mar 2002 10:42:23 -0600 Subject: [Edu-sig] Re: The right learning environment In-Reply-To: <4.2.0.58.20020321075815.00ad6520@pop3.norton.antivirus> Message-ID: [Kirby Urner] > PyCrust is certainly a useful tool -- last I checked, it > was a shell, w/o a text editor, and this would promote > the kind of unbundled approach you're advocating. And > as long as the shell is in the picture (and I prefer > GUI-based, but it's not mandatory), I think we're doing > Python justice. That is still the case. PyCrust is a shell plus a namespace tree view. The GUI is wxPython, to be precise. These days I find myself using IDLE most often as my editor, though I sometimes use Vim and Boa as well. --- Patrick K. O'Brien Orbtech From arthur.siegel@rsmi.com Thu Mar 21 18:36:42 2002 From: arthur.siegel@rsmi.com (arthur.siegel@rsmi.com) Date: Thu, 21 Mar 2002 13:36:42 -0500 Subject: [Edu-sig] Re: The right learning environment Message-ID: >Yet the latter is a wonderfuls scratch pad in which to test/learn >the basics of the language, with immediate feedback. >To bypass the shell is to make a huge pedagogical >error, IMO. Again - it was fundamental to my attraction to Python, and was used and is used by myself as an essential ingredient to a Python 'environment'. My counter-point - if any - is that it is particularly exciting as a feature when one understands it to be a builtin Python capacity. Mathias' experience is that there are Python users who don't understand the interactive prompt capabilities of Python, and rightl;y bemoans the fact. Don't know who those users are or how they got that way. I make the more minor point that it is a shame if folks would misunderstand that the interactive promt is something brought to them by and available only through IDLE. Though I find IDLE an elegant and fully satisfactory way to get at it. How to get it all? Art From arthur.siegel@rsmi.com Thu Mar 21 18:45:18 2002 From: arthur.siegel@rsmi.com (arthur.siegel@rsmi.com) Date: Thu, 21 Mar 2002 13:45:18 -0500 Subject: [Edu-sig] Re: The right learning environment Message-ID: >I don't find that sad. It's good news. Here and elsewhere >among Pythonistas, I think you'll find little argument re >Python's suitability as a teaching language. Only preaching >to the choir is what'd be sad. In fact 'only preaching' would be sad. As are you, I am well past preaching and well into doing. Art From urnerk@qwest.net Thu Mar 21 20:05:21 2002 From: urnerk@qwest.net (Kirby Urner) Date: Thu, 21 Mar 2002 12:05:21 -0800 Subject: [Edu-sig] Re: The right learning environment In-Reply-To: Message-ID: <4.2.0.58.20020321114923.01a0e5e0@pop3.norton.antivirus> At 01:36 PM 3/21/2002 -0500, arthur.siegel@rsmi.com wrote: >Mathias' experience is that there are Python users who >don't understand the interactive prompt capabilities of >Python, and rightl;y bemoans the fact. Don't know who >those users are or how they got that way. I don't think Mathias was directly discussing Python users. He's a Scheme guy. The DrScheme shell is specifically designed for teaching in that it allows the user to select the level of Scheme -- more features become available at higher levels. There's no chance anyone using his curriculum out of Rice University would ever miss the fact that PLT Scheme has a shell mode. They might miss if it has a non-shell mode, if they quit to early. Python users may sometimes miss the Python shell because they're self-tutoring over the internet and immediately think in terms of scripts ala programming languages with no shell mode. And for many, this remains the focus, as they're primarily interested in cgi type stuff (for example) -- the kinds of programs you leave running in the background while you, the programmer, catch some Zs (daemons). >I make the more minor point that it is a shame if folks would >misunderstand that the interactive promt is something brought >to them by and available only through IDLE. I agree. Equally a shame if they only use the Python shell in a DOS box, if in Windows, which environment is especially lame (i.e. no way to get to previously entered commands with an uparrow, except maybe in Win2000 and above). Compared with IDLE, I find the DOS shell to be extremely hard to use. In GUI world, I'd favor showing a sampling of shells, freeing students from the idea that there's only one way to go. So it should always be IDLE and... never IDLE only. The Linux text-based shell, in an X-Term window, is more usable. Kirby From mike@frcatel.fri.utc.sk Fri Mar 22 13:06:19 2002 From: mike@frcatel.fri.utc.sk (Michal Kaukic) Date: Fri, 22 Mar 2002 14:06:19 +0100 (CET) Subject: [Edu-sig] The right learning environment In-Reply-To: <4.2.0.58.20020321114923.01a0e5e0@pop3.norton.antivirus> Message-ID: Maybe, the following link will be of interest to all Python shell lowers: http://www-hep.colorado.edu/~fperez/ipython/ I like IPython and right now we use it in teaching of basics of Numerical Analysis (Python + Numeric + SciPy + Kmatplot beying used as a good substitute for commercial Matlab). Mike From matthias@ccs.neu.edu Fri Mar 22 13:54:10 2002 From: matthias@ccs.neu.edu (Matthias Felleisen) Date: Fri, 22 Mar 2002 08:54:10 -0500 (EST) Subject: [Edu-sig] The right learning environment In-Reply-To: (edu-sig-request@python.org) References: Message-ID: <20020322135410.C4465206F6@sualocin.ccs.neu.edu> Art, take a look at 200 and how the development of CGI servlets is totally integrated. Kirby explained the rest to you. -- Matthias From matthias@ccs.neu.edu Fri Mar 22 16:18:32 2002 From: matthias@ccs.neu.edu (Matthias Felleisen) Date: Fri, 22 Mar 2002 11:18:32 -0500 (EST) Subject: [Edu-sig] Re: Edu-sig digest, Vol 1 #494 - 7 msgs In-Reply-To: (edu-sig-request@python.org) References: Message-ID: <20020322161832.6B6E2206F6@sualocin.ccs.neu.edu> Not looking to knock DrScheme. But my experience was my experience. And hopefully I am not doing any harm by reporting my experience to Mathias. I have never experienced DrScheme in the context of a formal curriculum. And since that is how it is intended to be used, Mathias should not be shocked that perhaps it does not work quite as well outside of that kind of setting. No offense taken. I doesn't kill me if you guys don't understand the power of DrScheme. Just take a look at make executable, formerly called make launcher. Edit your programs with Emacs. Vi, for heaven's sake. Or ignore DrScheme and its lessons. Fine, too. -- Matthias From ajs@ix.netcom.com Sat Mar 23 00:18:31 2002 From: ajs@ix.netcom.com (Arthur Siegel) Date: Fri, 22 Mar 2002 19:18:31 -0500 Subject: [Edu-sig] Re: Edu-sig digest, Vol 1 #494 Message-ID: <000b01c1d200$454a1340$0334fea9@carol> Mathias write - >I doesn't kill me if you guys don't understand the power >of DrScheme. But does it bother you a little bit? Power we don't understand isn't power - as to us - at all. Theories how we got here? Seriously. Art From gherman@darwin.in-berlin.de Mon Mar 25 15:39:08 2002 From: gherman@darwin.in-berlin.de (Dinu Gherman) Date: Mon, 25 Mar 2002 16:39:08 +0100 Subject: [Edu-sig] Analyzing algorithms... References: <1014583999.1496.12.camel@robeson> Message-ID: <3C9F449C.770E1FD4@darwin.in-berlin.de> Jeffrey Elkner wrote: > > After attending Pai Chou's wonderful presentation, "Algorithm Education > in Python" at Python10, I got permission from the instructor of an > algorithms course I am currently taking to do our programming > assignments in Python (after first assuring him that they would not be > difficult to read ;-) > > Our first assignment is to implement merge and heap sort and then to > compare them empirically as to the number of assignments and comparisons > made by each. > > I've written the sorts. Does anyone have any suggestions as to the best > way to do the empirical analysis? Is there a better way than just > creating counters and then littering my code with increment statements? > > Please let me know if you have any ideas? > > Thanks! This is a very late contribution, but as I'm going through some of the hidden corners of my mailbox I might be able to add a comment, if you permit? I *think* sorting algorithms are compared using the number of compare and swap operations, so I assume by counting assign- ments you actually meant swap operations, isn't it? If so I believe the issue can be solved in the good old OO-way by creating an abstract sorting base class with concrete sub- classes of it. My preference would something like this (with visualising calls commented): --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- class Sorter: """An abstract sorting class. This contains hooks for swapping and comparing elements to be implemented in subclasses. Other methods could be filled in for visualising the algorithm used (and/or be called on respective delegates). """ def __init__(self): self.cmpCount = 0 self.swapCount = 0 def __call__(self, aList=None): self.sort(aList) def swap(self, aList, i, j): self.swapCount = self.swapCount + 1 L = aList L[i],L[j] = L[j],L[i] def compare(self, aList, i, j): self.cmpCount = self.cmpCount + 1 L = aList return cmp(L[i], L[j]) def sort(self, aList): raise "NotImplemented" class BubbleSort(Sorter): def sort(self, aList): L = aList # SHOW_bereich_quickest(0, len(L)-1) for x in range(len(L)): for z in fullrange(0, len(L)-2): # SHOW_element1(z) # SHOW_element2(z+1) if self.compare(L, z, z+1) >= 0: self.swap(L, z, z+1) # SHOW_zeig([z, z+1]) bs = BubbleSort() print bs.__class__.__name__ L = [9, 5, 2, 7, 6, 1, 3] print L bs(L) print L args = (bs. cmpCount, bs.swapCount) print "compares: %d, swaps: %d" % args --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- With some slight modifications you can plug this directly into the code posted by Gregor Lingl, replacing the bubble function with the following code like this: --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- class Sorter: def __init__(self, aList=None): self.cmpCount = 0 self.swapCount = 0 return self(aList) def __call__(self, aList=None): return self.sort(aList) def swap(self, aList, a, b): self.swapCount = self.swapCount + 1 L = aList L[a],L[b] = L[b],L[a] def compare(self, aList, a, b): self.cmpCount = self.cmpCount + 1 L = aList return cmp(L[a], L[b]) def sort(self, aList): return aList ############################################################## ## BubbleSort und Verwandte class bubble(Sorter): def sort(self, aList=None): global L SHOW_bereich_quickest(0,len(L)-1) for x in range(len(L)): for z in fullrange(0,len(L)-2): SHOW_element1(z) SHOW_element2(z+1) if self.compare(L, z, z+1) >= 0: self.swap(L,z,z+1) SHOW_zeig([z,z+1]) --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- Jeff, does this also solve your problem, or is anything fun- damentally wrong with it? At least you don't have to implement many double underscore methods... Of course, I know more recent Python versions have function attributes, but then, strictly speaking, they aren't func- tions any more. Regards, Dinu -- Dinu C. Gherman ................................................................ "The world becomes a better place as a result of the refusal to bend to authority and doctrine." (Noam Chomsky)