| Home | Trees | Indices | Help |
|
|---|
|
|
object --+
|
Parameterized
Base class for named objects that support Parameters and message formatting.
Automatic object naming: Every Parameterized instance has a name parameter. If the user doesn't designate a name=<str> argument when constructing the object, the object will be given a name consisting of its class name followed by a unique 5-digit number.
Automatic parameter setting: The Parameterized __init__ method will automatically read the list of keyword parameters. If any keyword matches the name of a Parameter (see Parameter class) defined in the object's class or any of its superclasses, that parameter in the instance will get the value given as a keyword argument. For example:
- class Foo(Parameterized):
- xx = Parameter(default=1)
foo = Foo(xx=20)
in this case foo.xx gets the value 20.
Message formatting: Each Parameterized instance has several methods for optionally printing output according to the current 'print level', such as SILENT, WARNING, MESSAGE, VERBOSE, or DEBUG. Each successive level allows more messages to be printed. For example, when the level is VERBOSE, all warning, message, and verbose output will be printed. When it is WARNING, only warnings will be printed. When it is SILENT, no output will be printed.
For each level (except SILENT) there's an associated print method: Parameterized.warning(), .message(), .verbose(), and .debug().
Each line printed this way is prepended with the name of the object that printed it. The Parameterized.print_level parameter and the module global variable min_print_level combine to determine what gets printed. For example, if foo is a Parameterized:
foo.message('The answer is',42)
is equivalent to:
- if max(foo.print_level,parameterized.min_print_level) >= MESSAGE:
- print foo.name+':', 'The answer is', 42
|
|||
|
__metaclass__ The metaclass of Parameterized (and all its descendents). |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Inherited from |
|||
|
|||
|
|||
|
|||
|
|||
name = Parameter(default= None, constant= True, doc= String identifier for this object. |
|||
print_level = Parameter(default= MESSAGE, precedence=-1)
|
|||
|
|||
|
Inherited from |
|||
|
|||
Print each of the given args iff print_level or self.db_print_level is greater than or equal to the given level. Any of args may be functions, in which case they will be called. This allows delayed execution, preventing time-consuming code from being called unless the print level requires it. |
|
Initialize this Parameterized instance. The values of parameters can be supplied as keyword arguments to the constructor (using parametername=parametervalue); these values will override the class default values for this one instance. If no 'name' parameter is supplied, self.name defaults to the object's class name with a unique number appended to it.
|
Provide a nearly valid Python representation that could be used to recreate the item with its parameters, if executed in the appropriate environment. Returns 'classname(parameter1=x,parameter2=y,...)', listing all the parameters of this object.
|
Restore objects from the state dictionary to this object. During this process the object is considered uninitialized. |
|
Print a warning if params contains something that is not a Parameter of this object. Typically invoked by a __call__() method that accepts keyword arguments for parameter setting. |
|
Initialize default and keyword parameter values. First, ensures that all Parameters with 'instantiate=True' (typically used for mutable Parameters) are copied directly into each object, to ensure that there is an independent copy (to avoid suprising aliasing errors). Then sets each of the keyword arguments, warning when any of them are not defined as parameters. Constant Parameters can be set during calls to this method.
|
Return {parameter_name:parameter.default} for all non-constant Parameters. Note that a Parameter for which instantiate==True has its default instantiated. |
'optional @classmethod' A decorator that allows a method to receive either the class object (if called on the class) or the instance object (if called on the instance) as its first argument. Code (but not documentation) copied from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/523033.
|
'optional @classmethod' A decorator that allows a method to receive either the class object (if called on the class) or the instance object (if called on the instance) as its first argument. Code (but not documentation) copied from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/523033.
|
'optional @classmethod' A decorator that allows a method to receive either the class object (if called on the class) or the instance object (if called on the instance) as its first argument. Code (but not documentation) copied from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/523033.
|
classmethod(function) -> method Convert a function to be a class method. A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:
It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument. Class methods are different than C++ or Java static methods. If you want those, see the staticmethod builtin. |
classmethod(function) -> method Convert a function to be a class method. A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:
It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument. Class methods are different than C++ or Java static methods. If you want those, see the staticmethod builtin. |
'optional @classmethod' A decorator that allows a method to receive either the class object (if called on the class) or the instance object (if called on the instance) as its first argument. Code (but not documentation) copied from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/523033.
|
Restore the most recently saved state. See state_push() for more details. |
Save this instance's state. For Parameterized instances, this includes the state of dynamically generated values. Subclasses that maintain short-term state should additionally save and restore that state using state_push() and state_pop(). Generally, this method is used by operations that need to test something without permanently altering the objects' state. |
|
|||
nameString identifier for this object.
|
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Sun Oct 12 22:26:34 2008 | http://epydoc.sourceforge.net |