> > I want a way to get the contents in the order of their declaration, > > i.e. [B, A, D]. Does anyone know a way to get it? > > My suggestion would be to actually parse the text of the module. "Brute > force" is what it's called ;). But doing so with, say, pyparsing > shouldn't be *very* difficult. > > Just out of curiosity: Why do you need the order? > Thank you for your replies, and sorry for my late response.
Gabriel, unfortunately I am not a python expert so don't know how to play with module creation. I tried to look into __import__ function, but can't see a way to get what I want. Wildemar, your approach seems workable. I am going to have a look at it. Well, my requirement doesn't turn out to be an actual requirement now.:) I am using a web framework Django, that lets you define classes for database tables. The classes so defined can refer to other classes representing db tables. It also allows you to export those table data in a db-neutral format e.g. xml via the python classes so defined. Exporting does not require an order, but I thought that importing the data back may require data of classes which are referred by other classes to be present. I just verified that its not so. So I don't need to do it immediately. Nevertheless, it would be interesting to see how it can be done.:) -Ram -- http://mail.python.org/mailman/listinfo/python-list