3 Suggestions to Make Python Easier For Children

Brian Blais bblais at gmail.com
Tue Aug 5 07:36:17 EDT 2014


On Sat, Aug 2, 2014 at 2:45 AM, Mark Summerfield <list at qtrac.plus.com> wrote:
> Last week I spent a couple of days teaching two children (10 and 13 -- too big an age gap!) how to do some turtle graphics with Python. Neither had programmed Python before -- one is a Minecraft ace and the other had done Scratch.

When I've taught children (and adults!) with little programming
experience, I usually have a single import for all the things I want
them to use, something like:

from my_defined_functions import *

at the beginning of every script, usually named for the class I'm teaching.


>
> Suggestion #1: Make IDLE start in the user's home directory.

I use the iPython Notebook now for these things.

>
> Suggestion #2: Make all the turtle examples begin "from turtle import *" so no leading turtle. is needed in the examples.
>

in my universal import script I have the turtle imports, usually with
both from turtle import * and import turtle, so I have a choice.



> Suggestion #3: Make object(key=value, ...) legal and equiv of types.SimpleNamespace(key=value, ...).

 I also make a data structure, a simple wrapper around dict, which I
call Struct,  defined as:

class Struct(dict):

    def __getattr__(self,name):

        try:
            val=self[name]
        except KeyError:
            val=super(Struct,self).__getattribute__(name)

        return val

    def __setattr__(self,name,val):

        self[name]=val


then I can do:

x=Struct(a=5,b=10)
x.c=50
x['this']='that'  # or access like a dict


bb



-----------------

             bblais at gmail.com
             http://web.bryant.edu/~bblais



More information about the Python-list mailing list