jonny wrote: > I have a python code that manages some parameters using some variable > rules that may change from day to day. I'd like that the code will > self-modify according to rules parsed from a xml file: > > example: > > <rules> > <rule01> > <if> > <or> > <lessthan par_1="glicemyAtMorning" par_2="80"/> > <lessthan par_1="glicemyAtNight" par_2="80"/> > <and> > <greaterthan par_1="glicemyAtMorning" par_2="0"/> > <or> > <equalto par_1="urine" par_2="0"/> > <equalto par_1="urine" par_2="+/-"/> > <equalto par_1="urine" par_2="+"/> > </or> > </and> > </or> > </if> > <then> > <sendmessage>Something is wrong!</sendmessage> > </then> > </rule01> > <rule02> ... </rule02> > <rule03> ... </rule03> > </rules> > > Due to the fact that rules may change, I have to manage the python > program, parsing the whole xml file, and self-modify the python code > according to these variable rules. > How can I do?
So, essentially you are creating a dynamic language? But you already have one - python! Who's responsible for creating these rules, and what do they allow to be done? Because I'd rather use python snippets to define them, that you compile using the exec-function. If you insist on using XML, use some module like lxml to parse and create your own language constructs. Just a note: the use of "par_X" as attributes is unfortunate, to say the least. It doesn't allow for easy argument swapping, can cause troubles because you delete one attribute and miss renaming the others, and in general it's not good design to have arbitrary numbers of parameters. Instead, you better go with a nested param-tag. Diez -- http://mail.python.org/mailman/listinfo/python-list