Generate variables at run time?
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
> data is output from a train control system. Trains constantly enter
> leave the controlled territory, and each has a unique ID. I want to
> class named "train", and name each new instance based on this ID.
> example, train 123 will cause creation of T123=train(). While the
> in the system, it will be frequently updated based on new data, then
> 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