Generate variables at run time?

Terry Reedy tjreedy at udel.edu
Thu Jan 9 07:18:26 CET 2003


"Byron Morgan" <lazypointer at yahoo.com> wrote in message
news:Z77T9.276$V71.172 at newssvr19.news.prodigy.com...
> A server supplies an alphanumeric data stream over an internet
socket. The
> data is output from a train control system. Trains constantly enter
and
> leave the controlled territory, and each has a unique ID. I want to
use a
> class named  "train", and name each new instance based on this ID.
For
> example, train 123 will cause creation of  T123=train(). While the
train is
> in the system, it will be frequently updated based on new data, then
it will
> be destroyed when the train leaves the system.

What I would do is have a dict of trains.  When a new one enters the
system, add a corresponding instance of train to the dict keyed on
train id: trains[id] = train(initdata).  Keeping trains isolated in
their own namespace (dict) with be easier and *much* more useful than
adding them to the module namespace.  I can think of no advantage to
doing the latter.

Terry J. Reedy






More information about the Python-list mailing list