[melbourne-pug] mapping strings to class attributes/operators etc

Bruce Cropley cropleyb at yahoo.com.au
Sat Jan 7 22:53:54 CET 2006


Hi Patrick

> I've got a program I use to read in large files of
> data which I use to create temporary objects and
> apply various comparisons and criteria against the
> objects I create and write to different output files
> and increment various statistic attributes in my
> application object for later reporting.
>
> The problem is that this isn't a fixed operation at
> all. It would be much better for these comparisons
> and actions to be very dynamic and prevent me from
> constantly changing the code and rerunning it.

In compiled languages with lots of pain required to
build anything,
writing a mini-language makes a lot of sense.
Python is comparatively quick and easy to write and
modify, so you can
get something working without much effort.
Perhaps you're finding that it takes a long time to
process the data to
get to the point where you can run the queries, but
you need to try
a few different types of statistics. In this case, you
might want to
try embedding an interpreter into your application
using the "cmd" module,
or using "eval" like Justin suggested. Another option
would be to get the
app to "reload" a specific module that has this
summary processing in it.

The data that I've worked with in python apps like
this tends to have
been fairly easy to represent in a relational table or
two.
If you want to do Object Relational mapping, I've
heard good things about
a python library called SQLObject.
In my experience, if your data is fairly flat, then
you won't save on
the runtime by using an approach like the above,
because the data structures
that you need to gather the summary information can
change frequently.
In that case you could try a Pipeline design pattern
with different classes
for filters, accumulators etc, with a standard
interface calling from one
stage to the next.

Hope that helps,
Bruce


Send instant messages to your online friends http://au.messenger.yahoo.com 


More information about the melbourne-pug mailing list