From kirby.urner at gmail.com Wed Feb 1 15:31:13 2017 From: kirby.urner at gmail.com (kirby urner) Date: Wed, 1 Feb 2017 12:31:13 -0800 Subject: [Edu-sig] update from Silicon Forest In-Reply-To: References: Message-ID: Thank you Wes for all those excellent bookmarks, reminded me of when the Web was little more than personal pages, by those knowing enough HTML to hand code, and giving bookmarks (links) to other favorite places. That's value added for sure. This was pre search engine of any real power, so all the more so were these "sign posts" needed in Wild West days (W2 vs WWW or W3 -- name collisions I'm sure, so create a namespace, would ya?). Anyway, http://mybizmo.blogspot.com/2017/01/embedded-codester-apps.html (interested for whom it doesn't work, and also notice the turtle only sometimes draws the vertical bar to the hexagon (red), and per the penup and pendown code, to my eyes never should). ... might be interesting to some educators here. I'm showing off embedded Codester applications ("") written in an MIT Scratch like environment, deliberately so. For continuity. Kids get started in Scratch and transition to Codesters. The Python community oughta take note, cuz Codesters is Python (3.x). Windy day in PDX, I woke up respecting pilots (as in airplane pilots, but of course shipping can be hazardous also, not forgetting about trucking... huge pile up in California, like 50 vehicles... ). Speaking of trucking, that's another area where FoxPro has shined, the language I used prior to becoming a Python user (in spatial geometry mainly) and teacher (for O'Reilly, for Saisoft, for Coding with Kids). I'm sharing data about roller coasters in .csv format, comparing .csv to .json as data exchange formats. I'm talking about my night class, for adults, already deep into IT. Last night was "the API economy" (Apigee got swallowed up by Google awhile back, I noticed that). Front end: lots of eye candy, HTML + CSS a high art. Back end: straight data in bulk, wholesale, not really for human eyes though we like readability in principle (XML, JSON -- all those (but then XML might have huge chunks of munged binary data right, like base64? -- lots of "text" is just binary in disguise let's be clear). We use the csv reader object in the module by that name. I have them on Anaconda, using 3.5 -- I can boot up 3.6 and showcase features without asking them to have it locally. Back to trucking, I'm thinking of a coder, even older than me, with an extremely sharp intellect. I write about him in my blog here and there, transportation engineer by training. He has some C kernel code that optimizing routing better than the competition a lot of the time, around which he's layered FoxPro (VFP), but then more and more Python over time. Whatever I know of the trucking business is most likely through him. Actually maybe I don't mention him by name. That's OK. Truckologists would be able to zoom in. :-D OK, back to my day. Codesters, then meetup with Steve Holden, former PSF chairman and Pycon instigator (younger the EuroPython, that institution). He's just breezing through PDX on a lark, not staying in my company, plus I have to other guests to meet around the same time (from STL / St. Louis). I'm hoping to have Steve on my closed circuit Python radio/TV show tomorrow night. However he's off the hook in advance given the jet lag between PDX and the UK. Quite noticeable, right? Kirby -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Wed Feb 1 15:36:53 2017 From: kirby.urner at gmail.com (kirby urner) Date: Wed, 1 Feb 2017 12:36:53 -0800 Subject: [Edu-sig] update from Silicon Forest In-Reply-To: References: Message-ID: Thank you Wes, very much, for all those excellent bookmarks, reminded me of when the Web was little more than personal pages, by those knowing enough HTML to hand code, and giving bookmarks (links) to other favorite places. Great addition to the Python.org mailman archives for future reference for all of us. I used some of those swagger.io links in the message window during class just hours ago (I do one-way audio-video two-way text, private or to all). That's value added for sure. This was pre search engine of any real power, so all the more so were these "sign post" web pages needed in Wild West days (let's call that early web W2 as in "Wild West" vs WWW or W3, the more mature implementation we enjoy today, right? -- yes, name collisions abound, so create a namespace, would ya, just for me?). Anyway, http://mybizmo.blogspot.com/2017/01/embedded-codester-apps.html (interested for whom it doesn't work, and also notice the turtle only sometimes draws the vertical bar to the hexagon (red), and per the penup and pendown code, to my eyes never should). ... might be interesting to some educators here. I'm showing off embedded Codester applications ("") written in an MIT Scratch like environment, deliberately so. For continuity. Kids get started in Scratch and transition to Codesters. The Python community oughta take note, cuz Codesters is Python (3.x). Windy day in PDX, I woke up respecting pilots (as in airplane pilots, but of course shipping can be hazardous also, not forgetting about trucking... huge pile up in California, like 50 vehicles... ). Speaking of trucking, that's another area where FoxPro has shined, the language I used prior to becoming a Python user (in spatial geometry initially) and later teacher (for O'Reilly, for Saisoft, for Coding with Kids). I'm sharing data about roller coasters in .csv format, comparing .csv to .json as data exchange formats. I'm talking about my night class, for adults, already deep into IT. Last night was "the API economy" (Apigee got swallowed up by Google awhile back, I noticed that). Front end: lots of eye candy, HTML + CSS a high art. Back end: straight data in bulk, wholesale, not really for human eyes though we like readability in principle (XML, JSON -- all those (but then XML might have huge chunks of munged binary data right, like base64? -- lots of "text" is just binary in disguise let's be clear). We use the csv reader object in the module by that name. I have them on Anaconda, using 3.5 -- I can boot up 3.6 and showcase features without asking them to have it locally. Back to trucking, I'm thinking of a coder, even older than me, with an extremely sharp intellect. I write about him in my blog here and there, transportation engineer by training. He has some C kernel code that optimizing routing better than the competition a lot of the time, around which he's layered FoxPro (VFP), but then more and more Python over time. Whatever I know of the trucking business is most likely through him. Actually maybe I don't mention him by name. That's OK. Truckologists would be able to zoom in. :-D OK, back to my day. Codesters, then meetup with Steve Holden, former PSF chairman and Pycon instigator (younger the EuroPython, that institution). He's just breezing through PDX on a lark. Congrats to Charles for getting his poster proposal accepted at Pycon. I'll be there with him to co-explain. :-D Kirby PDX -------------- next part -------------- An HTML attachment was scrubbed... URL: From roberto03 at gmail.com Thu Feb 2 08:39:04 2017 From: roberto03 at gmail.com (Roberto Catanuto) Date: Thu, 2 Feb 2017 14:39:04 +0100 Subject: [Edu-sig] free falling object simulation Message-ID: Hi, a simple question for you: in this set of equations of the free falling body you have that the distance covered by the object in a time_interval = (average_velocity in that time_interval)*(that time_interval) http://www.physicsclassroom.com/class/1DKin/Lesson-6/Kinematic-Equations-and-Free-Fall When you simulate this phenomenon you have this set of equations where you read this line for the velocity: y1=y0+h*v0 My question is: why don't you have a 0.5 factor in this line? Here's the full code http://comput-physics.blogspot.ch/2011/06/simulation-free-fall-of-body.html Than you a lot. -- Roberto -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Fri Feb 3 03:35:13 2017 From: kirby.urner at gmail.com (kirby urner) Date: Fri, 3 Feb 2017 00:35:13 -0800 Subject: [Edu-sig] update from Silicon Forest (follow-up) Message-ID: > > OK, back to my day. Codesters, then meetup with Steve Holden, former PSF > chairman and Pycon instigator (younger the EuroPython, that institution). > He's just breezing through PDX on a lark. First, apologies for my prior post of this month appearing twice in the archives, some kind of failure on my end, in the middle of a send, resulting in a double-send. As one of the listowners, I could mess with it and delete one, but why at this point? My main business is to report about having Steve Holden as my guest on my Python TV show (a small group of students taking advantage of a professional development opportunity). Steve and I had about 30 minutes to rehearse using Zoom.us to pass control of the desktop around. I switched to him for demonstrations of MicroPython controlling continuously variable speed propellor gizmos. We were on separate floors of the building, but one staircase apart. One the outgoing video feed, we were able to get us both side-by-side as talking heads, so that Steve could both hold up his circuit board [1] and share his MicroPython shell, running on the other end of a USB connection.[2] Later in the program he showed with the Wing IDE looks like. We mostly look at Spyder, not exclusively (at least PyCharm, Eclipse, and IDLE will likely appear). For those just joining us, Steve, former PSF chairman, lives in the UK but just happens to be in Portland, an old haunt of his.[3] Students were engaged and asked good questions. Kirby [1] https://flic.kr/p/QwrS84 (Pyboard, paper diagram) [2] https://flic.kr/p/RGD4Hb (USB connection to Pyboard, in turn controlling two servo-mechanisms) [3] http://worldgame.blogspot.com/2011/02/open-secrets.html (Steve making a splash when moving to Portland in 2011, my personal journal -- blog -- entry). -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Sat Feb 11 19:22:38 2017 From: kirby.urner at gmail.com (kirby urner) Date: Sat, 11 Feb 2017 16:22:38 -0800 Subject: [Edu-sig] dual use __main__: work or test Message-ID: Does anyone use this pattern?: (a) accept command line parameters if __name__ == "__main__" or (b) run unittests if no parameters passed Something like: if __name__ == "__main__": if len(sys.argv)==7: command_line() else: unittest.main() I'm using this pattern with my classes, as a way of touching on both passing arguments from the command line (with nod to argparse for POSIX compliance), and self-contained testing. Maybe this would be better with doctest instead. I could do another version.... Example: https://github.com/4dsolutions/Python5/blob/master/tetravolume.py Kirby -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at handysoftware.com Sat Feb 11 20:59:10 2017 From: david at handysoftware.com (David Handy) Date: Sat, 11 Feb 2017 20:59:10 -0500 (EST) Subject: [Edu-sig] =?utf-8?q?dual_use_=5F=5Fmain=5F=5F=3A_work_or_test?= In-Reply-To: References: Message-ID: <1486864750.426729353@apps.rackspace.com> I often do something similar, but usually with a command-line option or sub-command to indicate whether to run tests instead of doing the normal thing, and my default is usually to do the normal thing, not run tests. However, many times I'll write a module not intended for use as a stand-alone script, but put some tests in it, and put an "if __name__ == '__main__'" thing in there that will unconditionally run tests. Then I can run that module's using the "-m" option, which I love: python -m module_name The test could use doctests, or even just call a function that has code with assert statements in it. I often use this technique when "bench-testing" a module under development. David H On Saturday, February 11, 2017 7:22pm, "kirby urner" said: Does anyone use this pattern?: (a) accept command line parameters if __name__ == "__main__" or(b) run unittests if no parameters passed Something like: if __name__ == "__main__": if len(sys.argv)==7: command_line() else: unittest.main() I'm using this pattern with my classes, as a way of touching on both passing arguments from the command line (with nod to argparse for POSIX compliance), and self-contained testing. Maybe this would be better with doctest instead. I could do another version.... Example: [ https://github.com/4dsolutions/Python5/blob/master/tetravolume.py ]( https://github.com/4dsolutions/Python5/blob/master/tetravolume.py ) Kirby -------------- next part -------------- An HTML attachment was scrubbed... URL: From jurgis.pralgauskis at gmail.com Sun Feb 12 07:00:53 2017 From: jurgis.pralgauskis at gmail.com (Jurgis Pralgauskis) Date: Sun, 12 Feb 2017 14:00:53 +0200 Subject: [Edu-sig] Turtle In-Reply-To: <6201FFB5-0C09-47A6-B732-1773C8908448@cse.msu.edu> References: <6201FFB5-0C09-47A6-B732-1773C8908448@cse.msu.edu> Message-ID: Trinket.io provides nice online infrastructure for py and turtle. You can build interactive course with it, example https://jurgis.trinket.io/programavimas-python#/pagrindai-duomenys-ir-veiksmai/galima-ir-piesti There is a nice collection of demos https://code.google.com/archive/p/python-turtle-demo/ 2017-01-26 17:56 "Richard Enbody" ra??: > One of the Hour of Code modules is built around Turtle: > https://hourofcode.com/capython > > On Jan 26, 2017, at 3:13 AM, Marcin Wojciechowski goleniow.edu.pl> wrote: > > > Hello, I teach computer science in elementary school. Looking for > information on turtle. I like very much and would like to apply it in the > classroom. > > Marcin Wojciechowski > http://marcinwojciechowski.edu.pl > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > https://mail.python.org/mailman/listinfo/edu-sig > > > > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > https://mail.python.org/mailman/listinfo/edu-sig > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Sun Feb 12 14:43:47 2017 From: kirby.urner at gmail.com (kirby urner) Date: Sun, 12 Feb 2017 11:43:47 -0800 Subject: [Edu-sig] Turtle In-Reply-To: References: Message-ID: On Thu, Jan 26, 2017 at 12:13 AM, Marcin Wojciechowski < marcin.wojciechowski at goleniow.edu.pl> wrote: > > Hello, I teach computer science in elementary school. Looking for > information on turtle. I like very much and would like to apply it in the > classroom. > > Marcin Wojciechowski > http://marcinwojciechowski.edu.pl > > Yes, there's a great deal of turtle literature out there. Python3 has a built in turtle module that plots to the native canvas object, as you probably know. https://docs.python.org/3.6/library/turtle.html Out-of-the-box Python3 might not be appropriate below a certain age naturally. What reading and writing skills do they have, and what patience for math? The original vision was to make math more fun ("hard fun") and use LOGO as a modality for imparting math concepts. These days the emphasis seems to be on splitting math from computer science even at the elementary school level, count me a skeptic this will be the best way. Those learning code + mathematics in tandem, along an integrated course of study, will likely pull ahead. Our schools in Portland (both public and private) seem to favor using MIT Scratch before introducing a lexical language, if doing programming with kids as young as 3rd or 4th grade. I'm not convinced there's a need to start that early, not that one size fits all (but in a traditional school, it kind of has to). The specific pilot program I'm involved in once a week (after school program, elective, costs extra) shifts them over to Codesters coming from Scratch. Codesters, like Scratch, is available in the cloud through a browser, so used with Chromebooks with Wifi in our case). If got links to some embedded examples from earlier this month, if curious. One of them (Hexagon) uses the built-in turtle. http://mybizmo.blogspot.com/2017/01/embedded-codester-apps.html The Martian Math one (appended) is deliberately way above their reading level but the challenge was simply to take printed sheets with the source code and match them with the corresponding applications. Connect the dots, so to speak. Eyeballing source just to pattern match is arguably a useful first step. I also get into some line-by-line analysis. Picture of white board from last class: https://flic.kr/p/RLSj5H Glad to see so many others chiming in. Kirby -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Sun Feb 12 14:47:41 2017 From: kirby.urner at gmail.com (kirby urner) Date: Sun, 12 Feb 2017 11:47:41 -0800 Subject: [Edu-sig] Turtle In-Reply-To: References: Message-ID: > Our schools in Portland (both public and private) seem to favor using MIT > Scratch before introducing a lexical language, if > The Martian Math one (appended) is deliberately way above their reading > level but the challenge was simply to take printed sheets with the source > code and match them with the corresponding applications. Connect the dots, > so to speak. > > The code below will not run in Python3 as it's cut and paste from the Codesters environment, which some new modules (sprites, stage...) to __builtins__ It's still Python though. """ I have one baseball and want to completely surround it with others. One way: put six around the center one on a table, then three on top, three on the bottom. With real baseballs, this would be difficult. To see an animation of what I'm talking about, check here: http://www.4dsolutions.net/ocn/graphics/cubanim.gif For a lot more on the mathematics, check here: http://oeis.org/A005901 """ stage.set_background("mars") sprite = codesters.Sprite("person10") sprite.go_to(0, -100) sprite.set_say_color("white") # for speaking def shell(n): """ input n should be a non-negative integer says how many balls in any layer """ if (not isinstance(n, int)) or n < 0: raise TypeError # signals we're done! if n == 0: return 1 # the central ball return 10 * n * n + 2 # otherwise, if n > 0 # put in a negative number to stop while True: # loop until TypeError is raised by user try: guess = int(sprite.ask("What layer number? (-1 to quit): >")) how_many = shell(guess) sprite.say("That layer has " + str(how_many) + " balls in it.") stage.wait(3) except TypeError: sprite.say("OK! Thanks for playing.") stage.wait(2) break sprite.say("Bye!") -------------- next part -------------- An HTML attachment was scrubbed... URL: From wes.turner at gmail.com Tue Feb 14 17:45:33 2017 From: wes.turner at gmail.com (Wes Turner) Date: Tue, 14 Feb 2017 16:45:33 -0600 Subject: [Edu-sig] dual use __main__: work or test In-Reply-To: References: Message-ID: On Saturday, February 11, 2017, kirby urner wrote: > Does anyone use this pattern?: > > (a) accept command line parameters if __name__ == "__main__" or > (b) run unittests if no parameters passed > > Something like: > > if __name__ == "__main__": > if len(sys.argv)==7: > command_line() > else: > unittest.main() > > I'm using this pattern with my classes, as a way of touching on both > passing arguments from the command line (with nod to argparse for POSIX > compliance), and self-contained testing. > https://en.wikipedia.org/wiki/POSIX - https://en.wikipedia.org/wiki/Exit_status - https://en.wikipedia.org/wiki/Exit_(system_call) - https://docs.python.org/3/library/signal.html#example - https://docs.python.org/3/library/atexit.html#atexit-example * - https://docs.python.org/3/library/sys.html#sys.exit returncode = range(0,128)[0] sys.exit(returncode) # https://docs.python.org/3.5/library/unittest.html#unittest.main sys.exit(unittest.main(exit=False)) # Running tests from the CLI def _main(argv=None) argv = list(argv) idx = argv.index('-t') if idx != -1: test_args = argv[idx+1:] argv.pop('-t') - https://docs.python.org/2.7/library/optparse.html - https://docs.python.org/3/library/argparse.html - http://click.pocoo.org/5/ In order to make main() testable, I like the following signature: def main(argv=None, stdin=None, stdout=None): argv = list(argv) # optparse/argparse output = func() return 0 def _main(): sys.exit(main(sys.argv)) if __name__ == "__main__": _main() def test_main_help(): retcode = _main(['-h',]) assert retcode == 0 retcode = _main(['--help',]) assert retcode == 0 ... in order to get test coverage for the main() entrypoint. Additional advantages of defining _main() and main(): - python -m modulename # should sys.exit - __main__.py - __init__.py:__main__ - setup.py console_script entry_points # should sys.exit - setup.py: 'scriptname = modulename:main' - https://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-creation > > Maybe this would be better with doctest instead. I could do another > version.... > Pytest | homepage: http://pytest.org | pypi: https://pypi.python.org/pypi/pytest | src: https://github.com/pytest-dev/pytest | docs: http://doc.pytest.org/en/latest/contents.html http://doc.pytest.org/en/latest/talks.html - Fixtures: - @pytest.fixture(scope=) - http://docs.pytest.org/en/latest/fixture.html - http://doc.pytest.org/en/latest/fixture.html#fixture-parametrize - Parametrizations: - @pytest.mark.parametrized - http://doc.pytest.org/en/latest/parametrize.html - Assertions - assert (with regular 'assert') - note that asserts are compiled out with 'python -O' - with pytest.raises - http://doc.pytest.org/en/latest/assert.html - Plugins - http://docs.pytest.org/en/latest/plugins.html#installing-external-plugins-searching - https://plugincompat.herokuapp.com/ - https://pivotfinland.com/pytest-sugar/ - https://github.com/zonca/pytest-ipynb (include 'assert' in Jupyter Notebook cells) - https://github.com/matplotlib/pytest-mpl - https://github.com/kevin1024/pytest-httpbin (great for learning HTTP w/ e.g. requests) - https://github.com/getsentry/pytest-responses (mock requests w/ responses) - https://github.com/manahl/pytest-plugins (shutil.Workspace.__exit__, .__del__) - https://github.com/pytest-dev/pytest-runner ($ python setup.py pytest ) - https://github.com/westurner?tab=stars&q=pytest > > > Example: > https://github.com/4dsolutions/Python5/blob/master/tetravolume.py > - unitest.main(exit=True) is the default - @pytest.mark.parametrized - sage - https://github.com/sagemath/sage/tree/master/src/sage/geometry - http://doc.sagemath.org/html/en/reference/geometry/ - http://doc.sagemath.org/html/en/reference/geometry/sage/geometry/polyhedron/constructor.html - http://doc.sagemath.org/html/en/reference/plot3d/#backends {Tachyon, Three.js} - http://doc.sagemath.org/html/en/reference/plot3d/sage/plot/plot3d/base.html - http://doc.sagemath.org/html/en/reference/plot3d/sage/plot/plot3d/platonic.html - https://github.com/sagemath/sage/blob/master/src/sage/plot/polygon.py Polygon > > > Kirby > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Fri Feb 17 16:53:17 2017 From: kirby.urner at gmail.com (kirby urner) Date: Fri, 17 Feb 2017 13:53:17 -0800 Subject: [Edu-sig] Prime Numbers... Message-ID: I have this segment in my Python course (which I wrote, see below) where I show prime number generator using an iterator written in two ways: as a generator function and as a class. Just for kicks, I cut and pasted the code to Codesters and discovered that, while it replicates Python3 syntax, it's not yet a complete implementation of the language. yield and next are not supported keyword and builtin respectively. No problem, I put in a workaround. http://mybizmo.blogspot.com/2017/02/prime-numbers.html (screen shots) https://www.codesters.com/preview/4183156df3fa49e1b12a4ab206d280af/ (runnable) I had my 5th-8th graders run the code having discovered the concept of "prime number" was already familiar. I threw out some numbers asking if they were prime. The 8th grade girl was not fooled by 51. I sketched "trial by division" very briefly on the whiteboard but did not do any careful reading of the Python code, as at this age it's enough to just eyeball the stuff and realize it cuts and pastes. The 2nd example below actually produces 3000 primes, not 30, despite the comment. :-D Thanks to Wes for links, still following 'em. Kirby PS: we also use MIT Scratch in this class. I'm still somewhat on a learning curve with that one. I got it to work for a Martian Math segment: http://controlroom.blogspot.com/2016/12/more-core.html What's Martian Math? http://wikieducator.org/Martian_Math http://www.4dsolutions.net/satacad/martianmath/toc.html # -*- coding: utf-8 -*- """ Created on Mon Mar 14 14:40:53 2016 @author: Kirby Urner Create an iterable that gives back successive prime numbers in two different ways: as a class and as a generator function. Trial by division involves accumulating all primes so far and admitting new candidates to the club only if no prime up to the sqrt of same, divides with no remainder. """ class Primes: def __init__(self): self.candidate = 1 self._primes_so_far = [2] # first prime, only even prime def __iter__(self): """I'm already an iterator so just return me as is""" return self def __next__(self): """proof I'm an iterator""" while True: self.candidate += 2 # check odds only from now on for prev in self._primes_so_far: if prev**2 > self.candidate: self._primes_so_far.append(self.candidate) return self._primes_so_far[-2] if not divmod(self.candidate, prev)[1]: # no remainder! break def primes(): """generate successive prime numbers (trial by division)""" candidate = 1 _primes_so_far = [2] # first prime, only even prime yield _primes_so_far[-1] while True: candidate += 2 # check odds only from now on for prev in _primes_so_far: if prev**2 > candidate: yield candidate # surrender control at this point! _primes_so_far.append(candidate) break if not divmod(candidate, prev)[1]: # no remainder! break # done looping #p = Primes() # class based iterator #print([next(p) for _ in range(30)]) # next 30 primes please! p = primes() # generator function based iterator print([next(p) for _ in range(3000)]) # next 30 primes please! -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Fri Feb 17 23:47:24 2017 From: kirby.urner at gmail.com (kirby urner) Date: Fri, 17 Feb 2017 20:47:24 -0800 Subject: [Edu-sig] Prime Numbers... In-Reply-To: References: Message-ID: On Fri, Feb 17, 2017 at 1:53 PM, kirby urner wrote: > I have this segment in my Python course (which I wrote, see below) where I > show prime number generator using an iterator written in two ways: as a > generator function and as a class. > I have one other way of sharing the prime number trial by division thing: as coroutines. I owe David Beazley on this one. The coroutine decorator jumps us to the first yield so that we can send numbers in right away. primes weeds out composites, passing survivor primes to the printing coroutine (passed in as target). In my Tractor class, a simple object that plows a Field leaving a trail of Unicode characters (raster pattern), I used yield both to output and input (instances would gradually run low on fuel, but one could refill), but David advises against this pattern. http://mathforum.org/kb/message.jspa?messageID=9507410 (talks about Tractor Math) # -*- coding: utf-8 -*- """ Created on Thu Oct 13 13:48:52 2016 @author: Kirby Urner David Beazley: https://youtu.be/Z_OAlIhXziw?t=23m42s Trial by division, but this time the primes coroutine acts more as a filter, passing qualified candidates through to print_me, which writes to a file. """ def coroutine(func): """ Advances decorated generator function to the first yield """ def start(*args, **kwargs): cr = func(*args, **kwargs) cr.send(None) # or next(cr) or cr.__next__() return cr return start @coroutine def print_me(file_name): with open(file_name, 'w') as file_obj: while True: to_print = (yield) file_obj.write(str(to_print)+"\n") @coroutine def primes(target): _primes_so_far = [2] while True: candidate = (yield) for prev in _primes_so_far: if not divmod(candidate, prev)[1]: break if prev**2 > candidate: _primes_so_far.append(candidate) target.send(candidate) break output = print_me("primes.txt") p = primes(output) for x in range(3, 200, 2): # test odds 3-199 p.send(x) with open("primes.txt", 'r') as file_obj: print(file_obj.read()) -------------- next part -------------- An HTML attachment was scrubbed... URL: From mhearne at usgs.gov Fri Feb 17 10:04:28 2017 From: mhearne at usgs.gov (Hearne, Mike) Date: Fri, 17 Feb 2017 08:04:28 -0700 Subject: [Edu-sig] Scipy 2017 "Teen Track" Message-ID: SciPy 2017, the sixteenth annual Scientific Computing with Python conference, will be held this July 10th-16th in Austin, Texas, at the AT&T Executive Education and Conference Center on the University of Texas campus. SciPy is a community dedicated to the advancement of scientific computing through open source Python software for mathematics, science, and engineering. The annual SciPy Conference allows participants from all types of organizations to showcase their latest projects, learn from skilled users and developers, and collaborate on code development. The Tutorial Committee is seeking an instructor for a new ?Teen Track? tutorial, aimed at high-school students who have some experience with programming (if statements, for loops and the like) and an interest in science. We expect these students will be attending SciPy with parents or will be from local area high schools. There will be a $2000 stipend awarded to the instructor. Submissions can be emailed to SciPy at enthought.com, and details of the requirements for submission can be found in the attached Request for Proposal. Thanks, The Scipy 2017 Tutorial Committee -------------- next part -------------- A non-text attachment was scrubbed... Name: RequestforProposalScipy2017TeenTrack.pdf Type: application/pdf Size: 58638 bytes Desc: not available URL: From kirby.urner at gmail.com Sat Feb 18 15:14:21 2017 From: kirby.urner at gmail.com (kirby urner) Date: Sat, 18 Feb 2017 12:14:21 -0800 Subject: [Edu-sig] properties and geometric shapes Message-ID: Ya'll know about @property and some my remember a few months back I was sharing about a Circle type where you could change the radius, area, or perimeter, by simply assigning to these attributes, and the other two would magically co-vary. Likely many people have thought of that. Great way to teach / learn geometry. Like this: >>> c = Circle() >>> c.area = 50 >>> c.radius 3.989422804014327 >>> c.circumference = 5 >>> c.radius 0.7957747154594768 https://github.com/4dsolutions/Python5/blob/master/circle2.py I don't think a math teacher needs to painstakingly go through all the code before using this API. Go ahead and work with finished programs. We'll look at the source code by and by. The goal is to interact with the instances as modeling geometric shapes with co-varying dimensions. I haven't done a Triangle class that way yet. That'd be fun to do. Nor a Tetrahedron, in any generic way, though I have some components lying around. :-D Having only one dimension change at a time, leaving others free to co-vary, makes for a good study in ripple effects. I've recently co-developed, with David Koski, another specimen of geometric object with co-varying properties. It's called a TetraBook and visually consists of a triangular book meaning both front and back covers are equilateral triangles, all edges 2, with a shared hinge (the book's spine). Imagine this book flat open on its back, with a single triangular page wagging back and forth, another equilateral triangle of edges 2. When it's all the way to one side, flat against either cover, there's no volume to speak of. When the page turns, however, the segments from page tip to each cover tip define two complementary tetrahedrons, the turning page their common face. What the TetraBook instance is allows is I can assign any of five attributes and, thanks to property methods behind the scenes, the other four with co-vary. The angle of the page, the lengths of the tip-to-tip segments, the volumes of the complementary tetrahedrons (same), their altitudes (same). I can even assign volume in two different ways, depending on what I consider my unit of volume (regular tetrahedron or right tetrahedron, the latter corresponding to a cube volume of edges 1). On Github: https://github.com/4dsolutions/Python5/blob/master/tetrabook.py (has a couple dependencies, also there: qrays.py and tetravolume.py) I recommend this approach to other math teachers. If your school also has a computer science department, so much the better right? Kirby lambda calc track oregon curriculum network 4dsolutions.net/ocn https://www.youtube.com/channel/UCr7TZxfhsqbeiQzLnHdgPgA -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Sun Feb 19 12:00:05 2017 From: kirby.urner at gmail.com (kirby urner) Date: Sun, 19 Feb 2017 09:00:05 -0800 Subject: [Edu-sig] Prime Numbers... In-Reply-To: References: Message-ID: Heres's a fix for the coroutine-based primes generator. It was trying to open a file that still wasn't closed, so would not print anything on first run (run it again, and the file from last time would print). I need to close that file at the end. The fix looks a bit inelegant, sending a -1 into the printer loop coroutine, triggering a StopIteration, which I catch. It should work now at least. Thanks to my buddy off list for testing it. # -*- coding: utf-8 -*- """ Created on Thu Oct 13 13:48:52 2016 @author: Kirby Urner David Beazley: https://youtu.be/Z_OAlIhXziw?t=23m42s Trial by division, but this time the primes coroutine acts more as a filter, passing qualified candidates through to print_me, which writes to a file. """ def coroutine(func): """ Advances decorated generator function to the first yield """ def start(*args, **kwargs): cr = func(*args, **kwargs) cr.send(None) # or next(cr) or cr.__next__() return cr return start @coroutine def print_me(file_name): with open(file_name, 'w') as file_obj: while True: to_print = (yield) if to_print == -1: break file_obj.write(str(to_print)+"\n") # print("File closed") @coroutine def primes(target): _primes_so_far = [2] while True: candidate = (yield) for prev in _primes_so_far: if not divmod(candidate, prev)[1]: break if prev**2 > candidate: _primes_so_far.append(candidate) target.send(candidate) break output = print_me("primes.txt") p = primes(output) for x in range(3, 200, 2): # test odds 3-199 p.send(x) try: output.send(-1) # tell print_me coroutine to quit, close file except: pass with open("primes.txt", 'r') as file_obj: print(file_obj.read()) -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Mon Feb 20 23:15:39 2017 From: kirby.urner at gmail.com (kirby urner) Date: Mon, 20 Feb 2017 20:15:39 -0800 Subject: [Edu-sig] a Triangle class (using @property) Message-ID: Regarding @property and covarying the dimensions of geometric shapes (Circle an example), I mentioned wanting to have a Triangle type for my middle school kids. The cloud-base Web browser based Codesters implementation of Python 3 is a dialect. No yield nor could I get @property to work, so made edges be method calls. https://www.codesters.com/preview/aaae86e39e61413b938ce3e5350515ca/ https://flic.kr/p/S86M6F (input console, triangle edges, area printed) https://flic.kr/p/S86Mfi (turtle graphics also drawn, behind the console) This Codesters version is a pared down full-blown 3.5 implementation on Github. https://github.com/4dsolutions/Python5/blob/master/triangles.py I'm not yet being as ambitious as I could be, defining rules for letting the user vary dimensions arbitrarily e.g. (1) change in area: resize to a similar triangle keeping all angles unchanged (2) change in edge: keep other two edges same length varying only opposite angle unless not possible, raise exception (3) change in angle: change opposite edge Given assignment to attributes (properties), the expectation is more "state change" of an object, versus obtaining a new immutable, as with strings. We're not calling, we're setting, the antithesis of the functional programming ideal, surrendering to objects with hidden state. In this implementation, I'm going with more of a read-only triangle. The initializer passes in vertexes A, B and C as (x,y) pairs and everything from then on is read-only. [2] The emphasis might be on learning about triangles, leveraging prior knowledge of Python syntax, or on leveraging prior knowledge about triangles to learn more about how to program in Python. I think it's a two way street. [3] Kirby PS: This thread over on math-teach is perking along.... http://mathforum.org/kb/thread.jspa?threadID=2838432 (expressing skepticism we can build competence through robot schools) [1] I first learned of Gattegno from Ian Benson at Pycon / Chicago the last year it was there, with connections to Stanford, including to Terry Winograd who knows Fernando Flores whom we had a Pycon 2016 keynote about as some might recall: https://youtu.be/ckW1xuGVpug?t=32m17s https://en.wikipedia.org/wiki/Terry_Winograd https://en.wikipedia.org/wiki/Fernando_Flores [2] Using __mul__ to implement scaling, returning a new Triangle, would make sense. That wouldn't be a state changer. [3] recycling my math teacher's lament (not quite the same as Lockhart's, though overlapping): https://medium.com/@kirbyurner/the-plight-of-high-school-math-teachers-c0faf0a6efe6 http://www.maa.org/external_archive/devlin/LockhartsLament.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: