From: Jack D. <ja...@pe...> - 2005-02-25 20:04:18
|
On Fri, Feb 25, 2005 at 02:04:57PM -0500, Abraham Schneider wrote: > Hmm.. you make good points. Generally I think it is better to keep > everything within python when possible (plus I am not a big fan of > XML..). I suspect in the end this ends up being a preference issue, but > here is the advantage I see with XML. Suppose I have code that reads > data from a file, and can display that data in several different views > (e.g. different variables, different outlays, etc. depending on what is > being examined). In the past I have written a seperate python program > per view that I need or allowed command line parameters to be passed. > > The difficulty with having separate python programs: > * Will have to either: > + run a different program per view I want > + pass a python program as a parameter to run (I don't want to have > to edit the main program for each new view have another import .. I > suppose one could put them all in the same directory, but this could be > a hassle for quick hacks). This isn't a big deal, since I've essentially > already advocated this for the config files. Somehow the semantics of > doing so under these circumstances seems different to me, and perhaps > more userfriendly to provide a layout language. > + continually reedit the same file with different parameters > > On the other hand, if everything is passed on the command line, I have > found it is difficult to get enough specifity to plot exactly I want, > without requiring several lines worth of parameters. > > So I see XML as a means of separating the layout of the data and > managing the different views, without having to touch the code at all. > In the end it doesn't really provide anything new, except for a > different method of doing the same thing. > Python imports don't have to be static, you can access modules dynamically just like you would XML files. For our web application we keep per-client information in .py files that gets __import__'d to modify the look & feel, setup default email addresses, etc. The modules just have to have some agreed on names. If they have a particular function it gets called with an object they can tweak. ex/ def apply_custom(client_id): try: custom = __import__('client_%d' % (client_id)) except ImportError: # nothing custom return def NOP(*args): return # do nothing function getattr(custom, 'alter_skin', NOP)(skin_object) getattr(custom, 'add_reports', NOP)(report_list) # etc The upshot is that you can use python modules just like you would use XML. They both contain markup, just different kinds. -Jack |