[EVALUATION] - E01: The Java Failure - May Python Helps?
Terry Reedy
tjreedy at udel.edu
Sat Feb 5 17:54:02 EST 2005
"Ilias Lazaridis" <ilias at lazaridis.com> wrote in message
news:cu2m3q$km1$1 at usenet.otenet.gr...
If you ask too much that other people do your searching for you, answers
will dry up. But here are a couple that you might not find on google
anyway, at least not easily.
> I want to add metadata to everything within my design (functions, data,
> classes, ...), if possible with a standard way.
You can annotate, by adding attributes to, modules, functions, classes, and
class instances. You can not directly do so with 'basic' types: numbers,
sequences, and dicts -- and some others. You can, however, either extend
or wrap anything with your own classes to get something you can annotate
(but don't ask me for the details).
> I want to generate things (code, txt, html etc.) out of my object-model,
> whilst using with a flexible generator, if possible a standard one.
One standard way to generate text from objects is to use custom classes,
each with a custom __str__ method. Assuming you have a hierachical model
without loops, each such method can recursively call each data attribute
object of the instancefor it to generate its substring. (With loops you
need a loop-cutting mechanism to prevent infinite recursion.) I know this
has been done for html (but again, I won't google for you). Define a class
for each type of element and give each instance a list of element instances
it contains. Then 'print html_doc_instance' can print the html doc
corresponding to the object model.
Like others, I recommend you spend a day with Python if you wish to learn
more.
Terry J. Reedy
More information about the Python-list
mailing list