[Tutor] best way to dynamically set class variables?

Alan Gauld alan.gauld at yahoo.co.uk
Wed Nov 7 20:21:51 EST 2018


On 07/11/2018 23:06, Alan Gauld via Tutor wrote:

>> Imagine having to write this for 100 columns, brrr.
> 
> No problem, I've done that dozens of time for production C++ code,
> it's business as usual in commercial programming.
> 
> Of course I'd get the data from a meta SQL query and feed it into an
> emacs macro to generate the code but I'd still have to churn out the
> class definitions. (Or I might even write a Python program to generate
> the C++ code for me) But it's eminently doable and keeps the rest of the
> code simple.
It just occurred to me that this bit of C++ nostalgia might
not be as irrelevant as I first thought.

A simple approach you could use would be to get Python to
generate a new python file(module) containing the required class
definition (simple string processing) and then dynamically
import the new file.

Very similar to my emacs macro approach except with dynamic
loading.

You'd probably need a batch/cron job to version control
all these new files too...

And I've no idea how efficient that would be if there were
a lot of tables to be processed - but in that scenario I suspect
the whole class per table approach is flawed!

Just a thought... or 3...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list