c# - Determine Declaring Order of Python/IronPython Functions -


i'm trying take python class (in ironpython), apply data , display in grid. results of functions become columns on grid, , order of functions order of columns. there way determine order of python functions of class in order declared in source code? i'll take answers use either ironpython or regular python.

so instance, if have class:

class foo:     def c(self):         return 3     def a(self):         return 2     def b(self):         return 1 

i (without parsing source code myself) list of [c, a, b]. ideas?

as caveat, ironpython used keep references of functions in order declared them. in .net 4, changed behavior match python (which lists them in alphabetical order).

in python 2.x (ironpython on python 2) answer unfortunately no. python builds dictionary of class members before creating class object. once class created there no 'record' of order.

in python 3 metaclasses (which used create classes) improved , can use custom object instead of standard dictionary collect class members class built. allows know order.

however, ironpython there hack might work. python dictionaries inherently unordered - i.e. iterating on members of dictionary returns them in arbitrary (but stable) order. in ironpython used case that, accident of implementation, iteration return members in order inserted. (note may no longer case.)

you try:

 members = list(c.__dict__) # or c.__dict__.keys() 

you may find ordered hope for. unfortunately running code under different versions of ironpython (or other implementations of python) return them in different order.

another (better harder) approach use ast module (or ironpython parser) , walk ast find entries. not hard, more work.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -