[Tutor] How to control list input ?

Michele Alzetta michele.alzetta at aliceposta.it
Fri Jun 4 05:28:46 EDT 2004

Many thanks for the answers I've received so far. (I see that I probably
have to explain the nature of my problem better. Footnote for those who
are interested).

What my code actually attempts to do is create a template as a series of
dictionaries which get saved to disk (with the shelve module):

import shelve
class Template:

    def __init__(self,doctdbname,abdbname,schemadbname,shdbname):
        self.doctor = shelve.open(doctdbname, writeback = True)
        self.ability = shelve.open(abdbname, writeback = True)
        self.schematype = shelve.open(schemadbname, writeback = True)
        self.shifttype = shelve.open(shdbname, writeback = True)

    def various functions to insert, delete, obtain elements 
        from my dicts

I thought that the dictionaries would be like this:

Name     ||      key      ||         value

doctor   ||   doctor name ||     list of lists containing the data 
                                 to take into account when assigning
                                 the doc to a shift: hours worked 
                                 weekly, abilities, days set off by
                                 rules, off days  etc. etc. 

ability  || name of ability ||   list of doctors having that ability

schema   || name of shift     || days of week in which the shift exists 
            (e.g. emergency   || start time end time abilities required
            ward duty mornings) 

shift     || label of each            || doctor finally assigned:
          || single specific shift    || my output !
          || i.e. 0306-08-14-int-PN

Actually, maybe some of these are redundant. 
I'll find out coding along ....

We were talking about how to control list input for the list of lists
saved as a value in my doctor dictionary; one suggestion was to make
this a class, not a list of lists:

- is it possible for a dictionary to save a class as a value ? Would
this actually make sense in this case ?

Someone also suggests using dictionaries instead of lists:

- is it possible for a dictionary to save another dictionary as a 
value ?

Another solution proposed (maybe the simplest ?) is to write a list
structure checking function.

Any comments and suggestions appreciated !


ER doctors have hectic lives and weird shifts. Preparation of a month's
shift schedule takes up entire afternoons, and no matter how many of us
check the schedule you always end up discovering somebody is supposed to
be in two places contemporaneously. So I thought a good way of learning
python might be to try to make a Python Emergency Physician Scheduler
allows one to create and save a template of what the shifts are like (in
the emergency department at a given moment there are up to 5 different
doctors on duty doing different things); the template also takes into
account that different types of shifts require different abilities; that
some doctors can be assigned to any shift whereas others may not be
assigned to certain types of shift because they do not have certain
abilities; it takes into account that different doctors have different
working hours, and that some have more days holiday left over than
others too. The program should be capable of acquiring a list of rules
(doc A must be allowed these 3 days off because he's at a Congress, doc
B must be home every wednesday evening, docs C and D are willing to do 2
consecutive 6 hour shifts of a certain type, doc E must not work nights,
doc F prefers working afternoons raher than mornings but will of course
do both etc etc). It must then fill in my template for the current
month, by assigning a doctor to each shift while taking into account
working hours, rules and incompatiblities (for instance one cannot do
two consecutive long shifts, after a night shift he must be allowed at
least 24hours rest, one cannot be contemporaneously on duty in two
shifts etc). NB it is not possible to have a regular pattern in our
shifts (can't say for instance each does 2 mornings, 2 afternoons, 2
nights then 3 days off). Eventually a tidy schedule sheet would be the
output (in pdf format, for instance), and the the whole thing would have
to run in a GUI. 
At the moment I'm forgetting about the output part (import reportlab ?)
and the GUI part (wxwindows ?), I would like to concentrate on creating
a few classes and functions to deal with some of the basic problems. 
The actual quantity of data involved isn't very high, so I would like to
avoid databases. List comprehensions, import time, import calendar seem
to be the things to study for now ...

More information about the Tutor mailing list