1.5.3 Function

Functions are like the functions known to the Python interpreter, with the main difference that func_code is an EditableCode.

Function ([func])
If func is not supplied, create an emtpy Function object.

If func is a tuple or list, pass it to init_tuple.

Otherwise, pass func to init_function.

init_defaults ()
Set all the fields to more or less arbitrarily guessed default values.

init_func (func)
Initialize all fields from func.

make_function ()
Return a function to reflect the current state of the object.

init_tuple (tup)
Initialise the object from the tuple tup.

as_tuple ()
Return a convenient picklable (or probably even marshallable) tuple that can be used to initialise a Function.

Once again I've lazily copied the attribute definitions from the language reference.

func_name
__name__
func_name or __name__ is the function's name.
func_doc
__doc__
func_doc or __doc__ is the function's documentation string, or None if unavailable.
func_code
func_code is the EditableCode object representing the compiled function body.
func_defaults
func_defaults is a tuple containing default argument values for those arguments that have defaults, or None if no arguments have a default value.
func_globals
func_globals is (a reference to) the dictionary that holds the function's global variables -- it defines the global namespace of the module in which the function was defined.
method
If the function is in fact a method, this is the InstanceMethod. Otherwise this attribute doesn't exist.

Send comments to mwh@python.net