From urnerk at python.org Fri Jul 16 09:17:46 2004 From: urnerk at python.org (Kirby Urner) Date: Fri Jul 16 09:17:48 2004 Subject: [Edu-sig] Retrospective: Our Open Source class including Python In-Reply-To: Message-ID: <20040716071747.8D7A61E4002@bag.python.org> So I just finished a chapter in collaboration with Jerritt Collord, a gifted young man from Nevada with Linuxfund.org, who graciously contributed his time to the Saturday Academy (whereas I charged a fee -- but Linuxfund reimbursed him), to work out 'Adventures in Open Source' a first time offering. Saturday Academy is a nonprofit working with high school aged and younger students looking for experiences that take them outside the usual classroom fare, giving them exposure to working engineers, artists, scientists, musicians or whatever flies (and passes quality control). I consider it a privilege to work with this outfit, spearheaded by Joyce et al out of Portland State University. A challenge this particular time was Satacad had been working with police in the Hillsboro area to fulfill the chief of police guy's mission to bridge the digital divide -- something he's passionate about, and will bend the rules to do. To this end, these police had setup a RedHat 9.0 lab right off the main lobby of their West Precinct. That was to be the site of our class. You could tell even the parents wondered about this venue, as they left their teenagers (all boys this time) in our care. Like I said, this was a pilot course, a first time offering, there was lots to be worked out. But one thing we all agreed on: open source begins with source code being a focus, and the ability to read and write source code, i.e. to engage with the principle currency of the realm, was important for entre. It'd feel too watered down if we didn't get into some serious programming (not just HTML or something). And we selected Python for this job (I was sold on this idea from the beginning, and Jerritt had no problem with it, although he is a fan of Squeak and Alan Kay's level of commitment (not implying I'm not an admirer of Squeak -- I am, especially of what it does in the hands of skilled Squeakers). The course provided me with a good opportunity to field test a lot of my ideas about mixing Python with geometry (simple, static stuff to start -- didn't even get VPython to compile in time; these Red Hat 9.0 boxes started in a fairly primitive state, no gcc even, to compile Python with, and no CDs; we did it all over the internet (with Jerritt setting that part up, with help and support from Phil et al of the HBPD)). Course materials: we're working on synthesizes our work and have more literature developed than is currently online. However, at my web site is a snapshot with quite a bit of our materials. Regarding Python, I'd be especially interested in feedback on my paper under the Background subdirectory (the PDF). I wrote it partly in response to Ryan's request for more theory. I also just fixed a typo (added a 'd', changed version from 1.1 to 1.2). The kids were very engaged and learned a lot. The course was considered a success and we're planning to offer it again in the fall, although Jerritt is moving out of town shortly, so the chemistry and configuration will be different. This was a really good episode. Kirby Website: http://www.4dsolutions.net/satacad/ PS: I also offered to teach a math-through-programming course starting Jan 2005 (some different, some partially overlapping content), still using Python, but also'd plan to phase in some J. From urnerk at qwest.net Fri Jul 16 15:42:12 2004 From: urnerk at qwest.net (Kirby Urner) Date: Fri Jul 16 15:42:15 2004 Subject: [Edu-sig] Addendum: re Satacad course & OSCON presentation In-Reply-To: <20040716071747.8D7A61E4002@bag.python.org> Message-ID: <20040716134213.5681C1E4005@bag.python.org> > i.e. to engage with the principle currency of the realm, was important for ^^^^^^^^^ principal Note: some of the resources we used included that youth-made mpeg about Python out of Yorktown High, by Jeff's students. I think that impressed 'em in part because Eric Raymond had already appeared as an authority in another documentary we pilot tested, so his coming out so positively about Python carried cred. And the human interest subplot was just dorky enough to keep their attention. I also pointed them to 'How to Think Like a Computer Scientist' and to the edu-sig page in general, as a good place to follow up (one of the students had ordered 'Learning Python' from Amazon, which I of course likewise endorsed). I'm cycling from Seattle to Portland over the next two days (through the weekend) and so there'll be a lag before I post any more to this list (not that we've not just had quite long silence). I'd like to discuss my upcoming OSCON presentation as well, if anyone is in the mood. I could likely improve my presentation as a result of such discussion. The PowerPoint I'll be using is at http://www.4dsolutions.net/oscon2004 (both ppt and pdf available). I cover a few topics we talked about here, including our work with NKS cellular automata via Tk, using Dr. Zelle's graphics.py. Kirby From ajsiegel at optonline.net Fri Jul 16 15:48:38 2004 From: ajsiegel at optonline.net (Arthur) Date: Fri Jul 16 15:49:51 2004 Subject: [Edu-sig] Retrospective: Our Open Source class including Python In-Reply-To: <20040716071747.8D7A61E4002@bag.python.org> Message-ID: <0I0Y00I0R6CZX5@mta2.srv.hcvlny.cv.net> > Regarding Python, I'd be > especially interested in feedback on my paper >under the Background > subdirectory (the PDF). Good stuff. I would only suggest you try to squeeze in something about the phenom one is observing when playing as follows. >>> class Mammal(object): def eat(self): print 'Munch' def sleep(self): print 'Zzzzzz' >>> hippo =Mammal() >>> hippo.eat() Munch >>> print hippo.eat > >>> eat=hippo.eat() Munch >>> print eat None >>> Art From ajsiegel at optonline.net Fri Jul 16 16:22:10 2004 From: ajsiegel at optonline.net (Arthur) Date: Fri Jul 16 16:22:14 2004 Subject: [Edu-sig] Retrospective: Our Open Source class including Python In-Reply-To: <20040716071747.8D7A61E4002@bag.python.org> Message-ID: <0I0Y003QG7WJSN@mta3.srv.hcvlny.cv.net> >And we selected Python for this > job (I was sold on this idea from the beginning, and Jerritt had no > problem > with it, although he is a fan of Squeak and Alan Kay's level of commitment > (not implying I'm not an admirer of Squeak -- I am, especially of what it > does in the hands of skilled Squeakers). Particularly in the context of "Adventures in Open Source", I think you made the appropriate choice. At the moment, I believe the Squeak license precludes it from meeting criteria of distributions such as Debian. But let's consider that a technicality. In spirit, Squeak - to me - is outside the mainstream of Open Source. It seems to have evolved as a world until itself. Python, as glue, draws its strength from its ability to help folks leverage other open source efforts. Cooperative and inter-operative technology is - to me - at the essence of the Open Source concept. Python had evolved into an important factor, and Guido, in the award handed to him, I think, by Raymond, was appropriately sited for his contribution to it. Squeak is way off to the side, IMO, in the context of Open Source and its significance. Art From david at handysoftware.com Fri Jul 16 17:14:03 2004 From: david at handysoftware.com (David Handy) Date: Fri Jul 16 17:11:31 2004 Subject: [Edu-sig] Retrospective: Our Open Source class including Python In-Reply-To: <20040716071747.8D7A61E4002@bag.python.org> Message-ID: On Fri, 16 Jul 2004, Kirby Urner wrote: > Saturday Academy is a nonprofit working with high school aged and younger > students looking for experiences that take them outside the usual classroom > fare, giving them exposure to working engineers, artists, scientists, > musicians or whatever flies (and passes quality control). I consider it a > privilege to work with this outfit, spearheaded by Joyce et al out of > Portland State University. I grew up in the Portland area. I am a Saturday Academy "alumni" from the 1980's. It's a great program. > Regarding Python, I'd be > especially interested in feedback on my paper under the Background > subdirectory (the PDF). I wrote it partly in response to Ryan's request for > more theory. I also just fixed a typo (added a 'd', changed version from > 1.1 to 1.2). Since operations in Python are normally accessed via built-in operators versus explicit method calls, and since you don't normally subclass int or float, I would not have led off my discussion of types and objects by using int and float as examples. Those types are more the exception than the rule, as far as how you use them. I think leading off with the Mammal class, hippo instance would have been more clear, and then afterwards say, "oh by the way, *everything* is an object, even int. Look at this: >>> (3).__add__(4) 7 See, you can even call methods on 3." > > The kids were very engaged and learned a lot. The course was considered a > success and we're planning to offer it again in the fall, although Jerritt > is moving out of town shortly, so the chemistry and configuration will be > different. This was a really good episode. > > Kirby > > Website: http://www.4dsolutions.net/satacad/ > Good stuff. I liked the scissors-paper-rock object lesson on why you want access to the source! With the youth I am teaching, I'm trying to use extending (and possibly "cheating") on a multi-player game as motivation. He/she who can code gets the advantage, knows the hidden commands that refuels your ship, etc. David H. From Scott.Daniels at Acm.Org Fri Jul 16 18:36:03 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri Jul 16 18:37:15 2004 Subject: [Edu-sig] Re: VPython In-Reply-To: References: Message-ID: Kirby Urner wrote: >> Do you know who I should contact >> (I expect the answer is sure)? > > Not sure whom to contact, but I bet povray.org gives some ideas. > ... > My goal is to have the same process work on either platform. But in > distributing this code, I wouldn't try to distribute povray as something > hidden or behind the scenes. I'd just say "get POV-Ray and install it -- > you can use it for *lot's* of other things, then enter a path to it here: [ > ]." Well, after a huge delay due to their strangely reimplementing the contact method, I finally have our answer: > It sounds fine to me, this is the sort of thing we like to see POV-Ray > doing. Feel free. > > regards, > -- Chris I'll try and push my changes back to VPython's website, anything more to include? -Scott David Daniels Scott.Daniels@Acm.Org From urnerk at qwest.net Mon Jul 19 20:19:25 2004 From: urnerk at qwest.net (Kirby Urner) Date: Mon Jul 19 20:19:29 2004 Subject: [Edu-sig] Retrospective: Our Open Source class including Python In-Reply-To: Message-ID: <20040719181927.E51791E4002@bag.python.org> > Since operations in Python are normally accessed via built-in operators > versus explicit method calls, and since you don't normally subclass int or > float, I would not have led off my discussion of types and objects by > using int and float as examples. Those types are more the exception than > the rule, as far as how you use them. > My thinking was colored by the parallel mathematics curriculum, wherein we start with natural numbers, then progress through integers, rationals, reals and complex. At each stage, a new type of number is introduced to address limitations of the earlier types. I'm thinking a good way to talk about types with kids is to go over this experience of gradually extending the number types in grade school, then talking about how "just numbers" is insufficient -- we need a date/time type, a string type, and so on. Note: When I developed a mod 7 int-like class, I didn't start by subclassing int, only by overloading some operators. My feeling is in subclassing int, I'm committed to overloading *all* the operators to make them consistent with mod 7 -- too big a commitment. > I think leading off with the Mammal class, hippo instance would have been > more clear, and then afterwards say, "oh by the way, *everything* is an > object, even int. Look at this: > > >>> (3).__add__(4) > 7 > > See, you can even call methods on 3." > That's good notation. I'd always put a space after the 3, as in 3 .__add__, but the paren style is better. > Good stuff. I liked the scissors-paper-rock object lesson on why you want > access to the source! With the youth I am teaching, I'm trying to use > extending (and possibly "cheating") on a multi-player game as motivation. > He/she who can code gets the advantage, knows the hidden commands that > refuels your ship, etc. > > David H. Or that elects your president? :-D Kirby From urnerk at qwest.net Mon Jul 19 20:21:57 2004 From: urnerk at qwest.net (Kirby Urner) Date: Mon Jul 19 20:22:02 2004 Subject: [Edu-sig] Retrospective: Our Open Source class including Python In-Reply-To: <0I0Y003QG7WJSN@mta3.srv.hcvlny.cv.net> Message-ID: <20040719182200.1A1151E4002@bag.python.org> > Particularly in the context of "Adventures in Open Source", I think you > made the appropriate choice. > Yes, I tend to agree. In open source world, Python is very mainstream. Squeak my have some appealing attributes, but it's not so well accommodated to the existing open source culture. > Squeak is way off to the side, IMO, in the context of Open Source and its > significance. > > Art Yes. Kirby From urnerk at qwest.net Mon Jul 19 20:26:32 2004 From: urnerk at qwest.net (Kirby Urner) Date: Mon Jul 19 20:26:36 2004 Subject: [Edu-sig] Retrospective: Our Open Source class including Python In-Reply-To: <0I0Y00I0R6CZX5@mta2.srv.hcvlny.cv.net> Message-ID: <20040719182635.2DEED1E4002@bag.python.org> > Good stuff. > > I would only suggest you try to squeeze in something about the phenom one > is > observing when playing as follows. > > >>> class Mammal(object): > def eat(self): print 'Munch' > def sleep(self): print 'Zzzzzz' > > >>> hippo =Mammal() > >>> hippo.eat() > Munch > >>> print hippo.eat > > > >>> eat=hippo.eat() > Munch > >>> print eat > None Indeed, I should include something along those lines. You're pointing out the difference between printing a result and returning one. Hippo.eat() prints to stdout (the terminal) but doesn't return anything, so the variable set up to receive its output gets the default return value for methods and functions (None) -- which is different than not being defined at all. My thanks to both yourself and David Handy for useful feedback. Appreciated. Kirby From billwinn at u.washington.edu Thu Jul 22 02:47:25 2004 From: billwinn at u.washington.edu (billwinn@u.washington.edu) Date: Thu Jul 22 02:47:29 2004 Subject: [Edu-sig] Snack question Message-ID: I'm a novice Python programmer who wants to use Snatch. I have everything installed correctly as far as I can tell. But when I try to play something I get an error that says I failed to set the number of channels. Here's what I get: >>> from Tkinter import * >>> root = Tk() >>> import tkSnack >>> tkSnack.initializeSnack(root) >>> snd=tkSnack.Sound() >>> snd.read('/usr/games/chromium/data/wav/music_game.wav') >>> snd.play() Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.2/site-packages/tkSnack.py", line 277, in play self.tk.call((self.name, 'play') + self._options(kw)) TclError: Failed setting number of channels. Any help will be most welcome. Thanks, Bil *************************************************************** * William Winn, * * 412 Miller, College of Education, Box 353600, * * University of Washington, Seattle, WA, 98195, USA. * * 206 685-1185, FAX 206 543-8439, billwinn@u.washington.edu * *************************************************************** From john.zelle at wartburg.edu Thu Jul 22 04:57:34 2004 From: john.zelle at wartburg.edu (John Zelle) Date: Thu Jul 22 04:58:13 2004 Subject: [Edu-sig] Snack question In-Reply-To: References: Message-ID: <40FF2D1E.80204@wartburg.edu> I've only tried to use snack once and had a similar problem playing sound files (although I did get it to generate nice tones). I resorted to using an external command for playing sound files (I use artsplay, because I run artsd for my sound system under Linux). I just used os.system() to fork the sound playing commands. Unfortunately, it's not portable, but it was quick and easy. I needed it as a replacement for Winsound on Linux. --John billwinn@u.washington.edu wrote: >I'm a novice Python programmer who wants to use Snatch. I have everything installed correctly as far as I can tell. But when I try to play something I get an error that says I failed to set the number of channels. Here's what I get: > > > >>>>from Tkinter import * >>>>root = Tk() >>>>import tkSnack >>>>tkSnack.initializeSnack(root) >>>>snd=tkSnack.Sound() >>>>snd.read('/usr/games/chromium/data/wav/music_game.wav') >>>>snd.play() >>>> >>>> >Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.2/site-packages/tkSnack.py", line 277, in play > self.tk.call((self.name, 'play') + self._options(kw)) >TclError: Failed setting number of channels. > >Any help will be most welcome. > >Thanks, > >Bil > >*************************************************************** >* William Winn, * >* 412 Miller, College of Education, Box 353600, * >* University of Washington, Seattle, WA, 98195, USA. * >* 206 685-1185, FAX 206 543-8439, billwinn@u.washington.edu * >*************************************************************** > > > > > > >_______________________________________________ >Edu-sig mailing list >Edu-sig@python.org >http://mail.python.org/mailman/listinfo/edu-sig > > > > From rodrigo.senra at terra.com.br Fri Jul 23 01:52:31 2004 From: rodrigo.senra at terra.com.br (Rodrigo Dias Arruda Senra) Date: Fri Jul 23 01:51:43 2004 Subject: [Edu-sig] Snack question In-Reply-To: <40FF2D1E.80204@wartburg.edu> References: <40FF2D1E.80204@wartburg.edu> Message-ID: <20040722205231.509fa42a@Goku> | | >I'm a novice Python programmer who wants to use Snatch. I have everything installed correctly as far as I can tell. But when I try to play something I get an error that says I failed to set the number of channels. Here's what I get: | > | > | > | >>>>from Tkinter import * | >>>>root = Tk() | >>>>import tkSnack | >>>>tkSnack.initializeSnack(root) | >>>>snd=tkSnack.Sound() | >>>>snd.read('/usr/games/chromium/data/wav/music_game.wav') | >>>>snd.play() | >>>> | >>>> | >Traceback (most recent call last): | > File "", line 1, in ? | > File "/usr/lib/python2.2/site-packages/tkSnack.py", line 277, in play | > self.tk.call((self.name, 'play') + self._options(kw)) | >TclError: Failed setting number of channels. | > | >Any help will be most welcome. I'm not a Snack expert, but have you tried with a different file other than '/usr/games/chromium/data/wav/music_game.wav' ? Perhaps this file uses more sound channels than your hardware have. Just a wild guess. best regards, Senra ,_ | ) Rodrigo Senra |(______ ----------------------------------------------- _( (|__|] GPr Sistemas http://www.gpr.com.br _ | (|___|] IC - Unicamp http://www.ic.unicamp.br/~921234 ___ (|__|] L___(|_|] ----------------------------------------------- From ken at joeys.org Fri Jul 23 03:49:05 2004 From: ken at joeys.org (ken) Date: Fri Jul 23 03:49:15 2004 Subject: [Edu-sig] problem with IF Message-ID: <41006E91.1030207@joeys.org> hello all, I have been trying to write a program to display the reading from a weather station. I was trying to change the direction of the wind from degrees to points of compass. Have tried various if.. elif.. but it seems to take the last option in the list regardless of the value of the degrees. # let's put in points of compass, instead of degrees dirnPoint = "N" print dirn if dirn >= 22: dirnPoint = "NE" print dirnPoint if dirn >77 : dirnPoint = "E" print dirnPoint if dirn >112 : dirnPoint = "SE" print dirnPoint if dirn > 157 : dirnPoint = "S" print dirnPoint if dirn > 202 : dirnPoint = "SW" print dirnPoint if dirn > 247: dirnPoint = "W" print dirnPoint if dirn > 292: dirnPoint = "NW" print dirnPoint if dirn > 345: dirnPoint = "N" print dirnPoint print dirn I added the prints to follow the progress through the chioces. Below is the printout from a sample direction;301 NE E SE S SW W NW N 301 To my way of thinking, it should have stopped at "W" but it seems to be getting TRUE for > 292 and > 345. Any ideas, please. Thanks.. ken Wallwork Computing Studies Co-ordinator St Joseph's College Hunters Hill NSW Australia ken@joeys.org ken@wyverntech.com From david at handysoftware.com Fri Jul 23 06:25:20 2004 From: david at handysoftware.com (David Handy) Date: Fri Jul 23 06:20:36 2004 Subject: [Edu-sig] problem with IF In-Reply-To: <41006E91.1030207@joeys.org> Message-ID: > hello all, > I have been trying to write a program to display the reading from a > weather station. I was trying to change the direction of the wind from > degrees to points of compass. Have tried various if.. elif.. but it > seems to take the last option in the list regardless of the value of the > degrees. The indentation of your program in the email was all messed up. My guess is that you wrote your program with a text editor that mixes spaces and tabs. That is a Very Bad Thing, especially with Python programs. The safest thing is to set up your editor so that it uses spaces instead of tab characters to indent. The IDLE editor that comes with Python does this by default. Here is my guess at how your program originally looked: # let's put in points of compass, instead of degrees dirnPoint = "N" print dirn if dirn >= 22: dirnPoint = "NE" print dirnPoint if dirn >77 : dirnPoint = "E" print dirnPoint if dirn >112 : dirnPoint = "SE" print dirnPoint if dirn > 157 : dirnPoint = "S" print dirnPoint if dirn > 202 : dirnPoint = "SW" print dirnPoint if dirn > 247: dirnPoint = "W" print dirnPoint if dirn > 292: dirnPoint = "NW" print dirnPoint if dirn > 345: dirnPoint = "N" print dirnPoint print dirn After I fixed the indentation on your program, and ran it with dirn=301, I got different results than you did: 301 NE E SE S SW W NW NW 301 This correctly says that 301 degrees is NW. > To my way of thinking, it should have stopped at "W" but it seems to be > getting TRUE for > 292 and > 345. No, NW is correct for 301 degrees. 301 is > 292. > Any ideas, please. I suspect that the mixed tab and space characters that caused the bad indentation in the email also caused Python to "misinterpret" your if statements. Try running Python with the -tt argument to do more checking for inconsistent tab usage, like this: python -tt compass.py To convert tabs to spaces in existing program files, try the untabify.py script that comes with Python. On Windows it is at: C:\Python23\Tools\Scripts\untabify.py or in the Python source code it is at: Tools/scripts/untabify.py Going forward, I strongly recommend that you set up your editor to always indent your Python programs with spaces instead of tab characters. See the Python style guide at: http://www.python.org/peps/pep-0008.html especially the section labled "Tabs or Spaces?", under "Code lay-out". I hope this helps - David H. On Fri, 23 Jul 2004, ken wrote: hello all, I have been trying to write a program to display the reading from a weather station. I was trying to change the direction of the wind from degrees to points of compass. Have tried various if.. elif.. but it seems to take the last option in the list regardless of the value of the degrees. # let's put in points of compass, instead of degrees dirnPoint = "N" print dirn if dirn >= 22: dirnPoint = "NE" print dirnPoint if dirn >77 : dirnPoint = "E" print dirnPoint if dirn >112 : dirnPoint = "SE" print dirnPoint if dirn > 157 : dirnPoint = "S" print dirnPoint if dirn > 202 : dirnPoint = "SW" print dirnPoint if dirn > 247: dirnPoint = "W" print dirnPoint if dirn > 292: dirnPoint = "NW" print dirnPoint if dirn > 345: dirnPoint = "N" print dirnPoint print dirn I added the prints to follow the progress through the chioces. Below is the printout from a sample direction;301 NE E SE S SW W NW N 301 To my way of thinking, it should have stopped at "W" but it seems to be getting TRUE for > 292 and > 345. Any ideas, please. Thanks.. ken Wallwork Computing Studies Co-ordinator St Joseph's College Hunters Hill NSW Australia ken@joeys.org ken@wyverntech.com _______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig From lha2 at columbia.edu Fri Jul 23 13:17:57 2004 From: lha2 at columbia.edu (Lloyd Hugh Allen) Date: Fri Jul 23 13:17:56 2004 Subject: Subject: Re: [Edu-sig] problem with IF Message-ID: <4100F3E5.8060109@columbia.edu> Two things. First, you want to use elif. Second, you want to go from most specific to least specific (or else to use a pair of bounds). I'm going to use a different example, because it would take too long to talk about eight cases. I think that you might have started with a nested if, but that will barely fit on your screen after eight indentations... Let's say that one is one, two is a couple, and three is many. I want to know how many widgets I have, and I'll start with what you have and see what happens. widget = 5 if widget >= 1: print "I have one widget" if widget >= 2: print "I have a couple of widgets" if widget >= 3: print "I have many widgets" and then the program dutifully prints I have one widget I have a couple of widgets I have many widgets This is a problem. We only want one case. To guarantee mutual exclusivity, we use elif, which is an abbreviation for else if. widget = 5 if widget >= 1: print "I have one widget" elif widget >=2: print "I have a couple of widgets" elif widget >=3: print "I have many widgets" except that now we get the unfortunate output I have one widget when we know in our heads that we have many widgets. This can be fixed by reversing the order of the cases--the condition widget >= 1 will be satisfied for every single value of widget that also >= 3, so we have to start with the widget >=3. widget = 5 if widget >= 3: print "I have many widgets" elif widget >=2: print "I have a couple of widgets" elif widget >=1: print "I have one widget" now the program hits the case that widget >= 3, sees that this is true, displays I have many widgets, and then STOPS. Which is good. It's also good to include an else at the end so that the program notifies you that an unexpected value (say, zero or a negative number) was encountered. widget = -5 if widget >= 3: print "I have many widgets" elif widget >= 2: print "I have a couple of widgets" elif widget >= 1: print "I have one widget" else: print "The value of widget is unexpected: " + `widget` the backquotes around the widget allow `widget` to act as a string; you can't otherwise concatenate a string with a numeric value, and I sense that I shouldn't talk about string formatting yet. And I'll ignore the possibility of a real-valued number of widgets--what would you do with 1.5 widgets anyway? Oh, and my email spell-checker went and turned all the "elif"s into "elf"s, so if I left an elf in there, please turn him back into an elif. Sorry. On an unrelated note: looking forward to Vancouver...looks like a good schedule. -Lloyd From holbert.13 at osu.edu Fri Jul 23 22:53:33 2004 From: holbert.13 at osu.edu (Rick Holbert) Date: Fri Jul 23 22:54:58 2004 Subject: [Edu-sig] problem with IF In-Reply-To: <41006E91.1030207@joeys.org> References: <41006E91.1030207@joeys.org> Message-ID: <200407231653.33604.holbert.13@osu.edu> Ken, I think you should check to see if the bearing is between two values as follows: #!/usr/bin/env python def dirnPoint(dirn): if dirn >= 345 and dirn < 22: return "N" elif dirn >= 22 and dirn < 77: return "NE" elif dirn >= 77 and dirn < 112: return "E" elif dirn >= 112 and dirn < 157: return "SE" elif dirn >= 157 and dirn < 202: return "S" elif dirn >= 202 and dirn < 247: return "SW" elif dirn >= 247 and dirn < 292: return "W" elif dirn >= 292 and dirn < 345: return "NW" inp = int(raw_input("Enter Bearing in degrees: ")) dir = dirnPoint(inp) print "%d degrees is %s" % (inp, dir) On Thursday 22 July 2004 21:49, ken wrote: > hello all, > I have been trying to write a program to display the reading from a > weather station. I was trying to change the direction of the wind from > degrees to points of compass. Have tried various if.. elif.. but it > seems to take the last option in the list regardless of the value of the > degrees. From ken at joeys.org Sat Jul 24 00:23:20 2004 From: ken at joeys.org (ken) Date: Sat Jul 24 00:23:38 2004 Subject: [Edu-sig] problem with IF In-Reply-To: <200407231653.33604.holbert.13@osu.edu> References: <41006E91.1030207@joeys.org> <200407231653.33604.holbert.13@osu.edu> Message-ID: <41018FD8.4050802@joeys.org> Thanks to all who responded to my problem. I had tried to use a text string for the right side of the comparison and originally a between values, using AND set of decisions. Also the original set of IFs was using elif but all had failed. The thing tht finally worked was making sure that the numeric for wind dirn was as an int. I thought I had used it as an int() previously and didn't look back at that 8-( Anyway, a simple dirn = int(dirn) has fixed the problem 8-) ken W Rick Holbert wrote: >Ken, > >I think you should check to see if the bearing is between two values as >follows: > >#!/usr/bin/env python > >def dirnPoint(dirn): > if dirn >= 345 and dirn < 22: > return "N" > elif dirn >= 22 and dirn < 77: > return "NE" > elif dirn >= 77 and dirn < 112: > return "E" > elif dirn >= 112 and dirn < 157: > return "SE" > elif dirn >= 157 and dirn < 202: > return "S" > elif dirn >= 202 and dirn < 247: > return "SW" > elif dirn >= 247 and dirn < 292: > return "W" > elif dirn >= 292 and dirn < 345: > return "NW" > >inp = int(raw_input("Enter Bearing in degrees: ")) > >dir = dirnPoint(inp) > >print "%d degrees is %s" % (inp, dir) > >On Thursday 22 July 2004 21:49, ken wrote: > > >>hello all, >>I have been trying to write a program to display the reading from a >>weather station. I was trying to change the direction of the wind from >>degrees to points of compass. Have tried various if.. elif.. but it >>seems to take the last option in the list regardless of the value of the >>degrees. >> >> >_______________________________________________ >Edu-sig mailing list >Edu-sig@python.org >http://mail.python.org/mailman/listinfo/edu-sig >-- >Scanned by The Sheriff - http://www.isheriff.com/ > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/edu-sig/attachments/20040724/e27f28b4/attachment.htm From john.zelle at wartburg.edu Sat Jul 24 02:42:21 2004 From: john.zelle at wartburg.edu (John Zelle) Date: Sat Jul 24 02:43:01 2004 Subject: [Edu-sig] problem with IF In-Reply-To: <200407231653.33604.holbert.13@osu.edu> References: <41006E91.1030207@joeys.org> <200407231653.33604.holbert.13@osu.edu> Message-ID: <4101B06D.9070801@wartburg.edu> Maybe this isn't really the forum, but I can't resist a couple quick comments on this example. Since this is a multiway decision (that is, 8 mutually exclusive outcomes based on a single decision value), elif is definitely appropriate but having two conditions on each clause is redundant and often leads to errors. In fact there is an error in the code below, since it can nver return 'N' (dirn can't be both >= 345 and < 22). Of course, North is a bit of a special case; one way to do that is to split "N" into its two cases: if dirn < 22: return "N" elif dirn < 77: return "NE" elif dirn < 112: return "E" elif dirn < 157: return "SE" etc... elif dirn < 345: return "NW" else: return "N" # anything >= 345 Also, if one is getting an int as input, you may as well use the input function (save raw_input for strings), then you won't accidently use a string as an int. dirn = input("Enter bearing in degrees: ") Of course, if this were embedded in a GUI, chances are you would be forced to get a string and do the conversion. --John ps. I can't help thinking there may be a more elegant way of doing the bearing conversion. Rick Holbert wrote: >Ken, > >I think you should check to see if the bearing is between two values as >follows: > >#!/usr/bin/env python > >def dirnPoint(dirn): > if dirn >= 345 and dirn < 22: > return "N" > elif dirn >= 22 and dirn < 77: > return "NE" > elif dirn >= 77 and dirn < 112: > return "E" > elif dirn >= 112 and dirn < 157: > return "SE" > elif dirn >= 157 and dirn < 202: > return "S" > elif dirn >= 202 and dirn < 247: > return "SW" > elif dirn >= 247 and dirn < 292: > return "W" > elif dirn >= 292 and dirn < 345: > return "NW" > >inp = int(raw_input("Enter Bearing in degrees: ")) > >dir = dirnPoint(inp) > >print "%d degrees is %s" % (inp, dir) > >On Thursday 22 July 2004 21:49, ken wrote: > > >>hello all, >>I have been trying to write a program to display the reading from a >>weather station. I was trying to change the direction of the wind from >>degrees to points of compass. Have tried various if.. elif.. but it >>seems to take the last option in the list regardless of the value of the >>degrees. >> >> >_______________________________________________ >Edu-sig mailing list >Edu-sig@python.org >http://mail.python.org/mailman/listinfo/edu-sig > > > > From drlinux at columbus.rr.com Sat Jul 24 04:09:32 2004 From: drlinux at columbus.rr.com (Dave Reed) Date: Sat Jul 24 04:09:37 2004 Subject: [Edu-sig] Re: problem with IF In-Reply-To: <4101B06D.9070801@wartburg.edu> References: <41006E91.1030207@joeys.org> <200407231653.33604.holbert.13@osu.edu> <4101B06D.9070801@wartburg.edu> Message-ID: <200407232209.32024.drlinux@columbus.rr.com> On Friday 23 July 2004 20:42, John Zelle wrote: > Maybe this isn't really the forum, but I can't resist a couple quick > comments on this example. > > Since this is a multiway decision (that is, 8 mutually exclusive > outcomes based on a single decision value), elif is definitely > appropriate but having two conditions on each clause is redundant and > often leads to errors. In fact there is an error in the code below, > since it can nver return 'N' (dirn can't be both >= 345 and < 22). Of > course, North is a bit of a special case; one way to do that is to split > "N" into its two cases: > > if dirn < 22: return "N" > elif dirn < 77: return "NE" > elif dirn < 112: return "E" > elif dirn < 157: return "SE" > etc... > elif dirn < 345: return "NW" > else: return "N" # anything >= 345 > > Also, if one is getting an int as input, you may as well use the input > function (save raw_input for strings), then you won't accidently use a > string as an int. > > dirn = input("Enter bearing in degrees: ") > > Of course, if this were embedded in a GUI, chances are you would be > forced to get a string and do the conversion. > > --John If all the directions had the same number of degrees (which I would think they should, but they didn't appear to in the example), it would make sense to me to divide by that number (after adding a constant as necessary) and using it as an index into a tuple like ('N', 'NE', 'E', 'SE', etc). Dave From holbert.13 at osu.edu Sat Jul 24 14:10:59 2004 From: holbert.13 at osu.edu (Rick Holbert) Date: Sat Jul 24 14:12:24 2004 Subject: [Edu-sig] problem with IF In-Reply-To: <4101B06D.9070801@wartburg.edu> References: <41006E91.1030207@joeys.org> <200407231653.33604.holbert.13@osu.edu> <4101B06D.9070801@wartburg.edu> Message-ID: <200407240810.59507.holbert.13@osu.edu> Thanks for the input John. Another idea for north is to test if it is >= 345 or < 22. Also, I've recommended your book to the CIS department here at OSU. Sincerely, Rick On Friday 23 July 2004 20:42, John Zelle wrote: > Maybe this isn't really the forum, but I can't resist a couple quick > comments on this example. > > Since this is a multiway decision (that is, 8 mutually exclusive > outcomes based on a single decision value), elif is definitely > appropriate but having two conditions on each clause is redundant and > often leads to errors. In fact there is an error in the code below, > since it can nver return 'N' (dirn can't be both >= 345 and < 22). Of > course, North is a bit of a special case; one way to do that is to split > "N" into its two cases: > > if dirn < 22: return "N" > elif dirn < 77: return "NE" > elif dirn < 112: return "E" > elif dirn < 157: return "SE" > etc... > elif dirn < 345: return "NW" > else: return "N" # anything >= 345 > From kent37 at tds.net Sat Jul 24 18:07:09 2004 From: kent37 at tds.net (Kent Johnson) Date: Sat Jul 24 18:07:12 2004 Subject: [Edu-sig] problem with IF Message-ID: <200407241607.i6OG79RT026683@outbound2.mail.tds.net> I cant' resist either. Here is the way I would do it. def degreesToDirection(deg): dirs = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'N'] ix = (int(deg) + 23) / 45 return dirs[ix] To test: for deg in [0, 21, 22, 45, 66, 67, 90, 135, 180, 225, 270, 315, 360]: print deg, degreesToDirection(deg) 0 N 21 N 22 NE 45 NE 66 NE 67 E 90 E 135 SE 180 S 225 SW 270 W 315 NW 360 N By the way this points out that the cutoff points in the original post are not evenly spaced and probably not what is wanted. It's easy to have Python tell you the correct cutoffs: >>> [ (45*i)+22 for i in range(8) ] [22, 67, 112, 157, 202, 247, 292, 337] Kent > ps. I can't help thinking there may be a more elegant way of doing the > bearing conversion. > From inxdr at yahoo.com.au Mon Jul 26 01:14:46 2004 From: inxdr at yahoo.com.au (Darren Payne) Date: Mon Jul 26 01:14:50 2004 Subject: [Edu-sig] Re: Edu-sig Digest, Vol 12, Issue 5 In-Reply-To: <20040723100003.C02651E4018@bag.python.org> Message-ID: <20040725231446.91933.qmail@web11205.mail.yahoo.com> Ken, I feel you may obtain the desired / expected result if you use elif instead of if ... other than the first if statement of course. e.g. if dirnpoint > xx: do this elif dirnpoint > xx: do that elif ......: do this instead give it a go and see what happens. regards Darren Payne Hurlstone Ag. ===== ----------------------------------------------------------------------------------- regards Darren Payne Hurlstone Agricultural High School Ph: 9829 9222 Fax: 98292026 __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail From urnerk at qwest.net Tue Jul 27 07:39:36 2004 From: urnerk at qwest.net (Kirby Urner) Date: Tue Jul 27 07:39:39 2004 Subject: [Edu-sig] OSCON anyone? In-Reply-To: <20040719182635.2DEED1E4002@bag.python.org> Message-ID: <20040727053938.7641F1E4002@bag.python.org> I'd like to know if anyone else subscribed to this list is attending OSCON in Portland these days, or has plans to show up shortly (it's just tutorial sessions these first couple of days -- I'm going through a 2-parter on wxPython tomorrow (Robin Dunn), caught the last half of one on Plone this AM (Joel Burton), did Subversion this afternoon (a CVS replacement...)). I visited the bookstore in the basement, bought Andy McKay's new book on Plone (which I hope he'll sign for me when he shows up later) -- but John Zelle's book wasn't in inventory (I specifically asked about it, as well as searching the stacks). I plan to plug it in my talk on Thursday, but I guess would-be buyers will need to find it on Amazon. Of course Guido will be here. I hope we have a chance to talk at least briefly. I'd have more chance to meet with Python folks were I attending VanPy, a Python conference in Vancouver, BC (Canada) immediately following OSCON. Unfortunately, I committed to doing a talk on Python for high school computer teachers during that time (on Aug 2) -- and then the talk was canceled, because all but one of the teachers signed up for 100% Java workshops (they'd never heard of Python, after all). They still haven't updated the website to reflect this cancellation: http://www.sao.org/programs/superquest.asp (search on Python). The Vancouver thing was already full by then, and I'd made no real plans, so I think I'll need to let that one get away. Ooo, I see Python 2.4 alpha is out. Kirby From urnerk at qwest.net Sat Jul 31 19:56:48 2004 From: urnerk at qwest.net (Kirby Urner) Date: Sat Jul 31 19:56:50 2004 Subject: [Edu-sig] Re: Teaching graphics with Python (was Introductoryhigh school programming) In-Reply-To: <409D1F3B.20705@wartburg.edu> Message-ID: <20040731175649.6DB6E1E4002@bag.python.org> > From: edu-sig-bounces@python.org [mailto:edu-sig-bounces@python.org] On > Behalf Of John Zelle > Sent: Saturday, May 08, 2004 10:56 AM > To: Kirby Urner; edu-sig@python.org > Subject: Re: [Edu-sig] Re: Teaching graphics with Python (was > Introductory high school programming) > For those of you working with VPython, if you've not tried it out yet, > take a look at the stereoscopic mode. I contributed the main code for > this in the fall of 2003. It's a spin-off from some VR work I've been > doing with my students. The stereo mode allows you to take virtually any > VPython program and turn it into true stereographic 3D. You can make the > objects seem to jump right out of the screen at you. The stereo graphics > are viewable in a variety of modes, but the really neat part is that you > can do it with no special equipment at all. Just set the stereo mode to > 'redblue' and you can use the cheap red-blue glasses that come with kids > books and happy meals (and are used for viewing Mars photos). You can > buy these glasses in bulk for pennies a piece and show true 3D programs > to a roomful of people using a standard LCD projector. Kids love this! > > Typically, making a program stereoscopic is as simple as doing: > scene.stereo = 'redblue' Hi John -- I wanted to thank you for this stereoscopic feature in VPython, and suggestion that I use it. I was sitting in Robin Dunn's tutorial on wxPython this Tuesday at OSCON when your suggestion drifted into my consciousness. I googled (OSCON had wifi) and lo and behold, found a 3D stereoscopy club and even a 3D *museum* right here in Portland ( http://www.cascade3d.org/ ). I emailed a guy and within 36 hours I had a whole stack of precisely those cheap red/blue glasses you described. I demoed quite a few things during my 45 minute talk, in addition to running through a bunch of slides in OpenOffice. The 3D thing came towards the end, and the audience (full room) went "ooooo" as the rhombic triacontahedron floated in front of them on the large screen, and "ahhhhhhh" as I rotated it and zoomed in to it. I also showed our cellular automata work using your graphics.py, which I mentioned, as well as holding up your book and talking about how important this was in the education side of things. My slides are here: http://www.4dsolutions.net/oscon2004/ (might be some minor problems if viewed in Windows, not sure (tried to make it work well in both, but kept finding little discrepancies going back and forth, and did all last minute editing on the Linux side)). People came up afterwards, and for the rest of the conference, saying how much they liked my talk. One guy said he was now persuaded to do Python in his CS1 next year (most of those present were not educators, but some advised on the side -- Dana Moore falls in this category (he showcased Python in Eclipse, so far mostly coded by : http://conferences.oreillynet.com/cs/os2004/view/e_spkr/524 ) The day before, I had a Middle Eastern lunch with your publisher, Jim Leisy (had never met him before) and Kevin Altis (main author of PythonCard and co-chair of the Python track at OSCON). Other highlights of the conference (from my point of view): --- Jim Hugunin showed the benchmarks for IronPython on the .NET framework -- it's working out very well (slower on Mono, but that project has more optimization to do). Jim starts work for Microsoft on Monday, so it'll be interesting to see under what terms further IronPython versions get out to our community http://conferences.oreillynet.com/cs/os2004/view/e_sess/5120 --- GvR's State of Python address introduced us to decorators, which offer a syntactic replacement for mymethod = staticmethod(mymethod) semantics in a class. He's going with @ (at sign), which he agrees looks unPythonic, but on the other hand there are good reasons for not inventing new key words. He knows this is controversial and is prepared to rip it out or change it if the community goes bananas. Decorators should be in the next alpha release of 2.4. He also talked about the new generator comprehensions and some of the subtleties involving late binding which could confuse people (more on that in a next post). http://conferences.oreillynet.com/cs/os2004/view/e_sess/4981 --- Alex Martelli gave a sophisticated presentation on Design Patterns, and as this preceded my talk, I was able to use 'fa?ade' as a part of my patter (I build a fa?ade, an adapter which limits the back end interface, into POV-Ray, VPython and the like). The other highlight re Alex was he and Anna just got married and shared slides and music from this event during the Lightning Talks. --- Michel Pelletier's talk overlapped a lot with Alex's. It was less about Zope3 and more about the importance of interfaces and adapters in Zope, PEAK and Twisted. He made a strong argument for bring interfaces into the syntax of Python in some way, so that Python would be able to compete effectively on these new multi-language VMs (.NET, Mono and Parrot). http://conferences.oreillynet.com/cs/os2004/view/e_sess/5298 --- I already mentioned the Python-in-Eclipse work, which is still beta, but coming along nicely. Andy McKay and Joel Burton did a very effective job presenting about Plone this time. Joel covered all the basics in a half day tutorial, and Andy focused on Archetypes, a technology for defining new data types within Plone without having to code too much. Andy, who has a new book out on Plone (Apress: http://www.apress.com/book/bookDisplay.html?bID=335 ), is the chief organizer behind VanPy (Python conference in Vancouver, BC) which starts like today or tomorrow. I'm not able to attend. Kirby From ajsiegel at optonline.net Sat Jul 31 22:00:43 2004 From: ajsiegel at optonline.net (Arthur) Date: Sat Jul 31 22:00:45 2004 Subject: [Edu-sig] Re: Teaching graphics with Python (was Introductoryhighschool programming) Message-ID: <0I1Q0082MFL4RQ@mta2.srv.hcvlny.cv.net> > I wanted to thank you for this stereoscopic feature in VPython, and > suggestion that I use it. Just thought I'd mention that VPython 3.0 has been released last week. This version is mostly a behind the scenes revamp of the code. VPython now uses the Boost Python library to expose Vpython's cvisual C++ code to Python. Among other things this allows one to directly subclass cvisual primitives in pure Python. Currently this is an undocumented facility as to VPython. But getting it down to its essentials, the following runs, and provides a sphere primitive that insists on being blue. import cvisual import time import atexit def __waitclose(): while not cvisual.allclosed(): time.sleep(0.05) atexit.register(__waitclose) scene = cvisual.display() class sphere (cvisual.sphere): def __init__( self,*args,**keywords): cvisual.sphere.__init__(self) self.color=(0,0,1) self.complete_init( self, self, 1, scene, None) s=sphere() Seems to me this facility will open up interesting new possibilities in having fun with VPython/cvisual. PyGeo for example could now decide to more truly wrap the cvisual library, as opposed to using it - through Vpython - as a rendering back-end. > > My slides are here: > http://www.4dsolutions.net/oscon2004/ (might be some minor problems if > viewed in Windows, not sure (tried to make it work well in both, but > kept finding little discrepancies going back and forth, and did all > last minute editing on the Linux side)). Looks super. Art