[IronPython] Partial classes

Michael Foord fuzzyman at voidspace.org.uk
Fri Jun 13 14:22:35 CEST 2008


Michael Stephens wrote:
> Our company has a scripting/macro system.  Functions are stored in a 
> database and at runtime we generate python classes.  For a form we 
> have multiple functions declared.  We want to use IronPython studio to 
> emit the python classes to a file to be debugged.  Is it possible to 
> build a partial class so that we can have one file per function.

Emit them as one file per function. Then have one file that imports them 
all and constructs a dictionary mapping function name to imported 
function. You can turn it into a class by calling:

new_class = type(name, (object,), dict_of_functions)

type is the default metaclass, and responsible for creating new classes. 
Every function will be a method of the new class.

Michael Foord
http://www.ironpythoninaction.com/


>
> file function324.py
> partial class Form76:
>  def function324.py
>
> file function325.py
> partial class Form76
>  def function324.py
>
> file base325.py
>  #do not edit anything in this file! changes will not be saved!
>
>
> Michael Stephens
>
> Electrical Engineering Graduate Student
> University of Wyoming
> falcon at uwyo.edu <mailto:falcon at uwyo.edu> or 89iroc at gmail.com 
> <mailto:89iroc at gmail.com>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   




More information about the Ironpython-users mailing list