dynamic assigments

scattered tooscattered at gmail.com
Thu Mar 24 23:17:01 EDT 2011


On Mar 24, 10:51 pm, scattered <tooscatte... at gmail.com> wrote:

[snip]

>  I can easily imagine other
> situations in which a user might want to create a large number of
> bindings for interactive use. Maybe as a teacher (I'm a math teacher)
> you have written a student-class which contains things like methods to
> compute averages, return lists of missing assignments, etc. At the
> prompt you run a script that creates a binding for each student in a
> section to a student object so that you can just type something like
> JohnDoe.missing() to get a list of their missing assignments. Just
> because exec() *can* be misused doesn't mean that there aren't valid
> uses for it. You would be foolish to run exec() on unparsed externally
> supplied data - but perhaps you are running it on data that you
> yourself have generated.
>

I think I might actually implement the above. A quick experiment with
IDLE's Python shell shows that an assigment generated by exec() is
immediately usable with autocomplete. Many of my students have weird
names like Victor Jarinski (a made-up but not untypical example).
Typing in average["Victor Jarinski"] for a dictionary look-up requires
a fair amount of typing, but if I have a top-level binding I can just
type Vic and then invoke auto-complete to get to
VictorJarinski.average() with a fraction of the key-strokes.

-scattered



More information about the Python-list mailing list