3 Suggestions to Make Python Easier For Children

Mark Summerfield list at qtrac.plus.com
Sat Aug 2 03:38:08 EDT 2014


On Saturday, 2 August 2014 08:14:08 UTC+1, Marko Rauhamaa  wrote:
> Mark Summerfield:
>
> > Suggestion #1: Make IDLE start in the user's home directory.
> 
> > Suggestion #2: Make all the turtle examples begin "from turtle import
> > *" so no leading turtle. is needed in the examples.
> >
> > Suggestion #3: Make object(key=value, ...) legal and equiv of
> > types.SimpleNamespace(key=value, ...).
> 
> Great suggestions for adults as well.
> 
> Expanding #3:
> 
>    >>> o = object()
>    >>> o.x = 3
>    Traceback (most recent call last):
>      File "<stdin>", line 1, in <module>
>    AttributeError: 'object' object has no attribute 'x'
> 
> Why?
> 
> Marko

object() returns a minimal featureless object with no dictionary (no __dict__ attribute). This makes sense for efficiency since not all objects need a dictionary.

What I'm suggesting is that _in addition_ to the existing behavior, a new behavior is introduced whereby object() called with keyword arguments creates a types.SimpleNamespace object (i.e., a basic object that has a dictionary initialized by the keyword arguments).

Mark.



More information about the Python-list mailing list