Param¶
- class igwn_ligolw.ligolw.Param(attrs=None)¶
Bases:
ElementParam element. The value is stored in the pcdata attribute as the native Python type rather than as a string.
Attributes Summary
The "DataUnit" attribute.
The "Name" attribute.
The "Scale" attribute.
The "Start" attribute.
The "Type" attribute.
The "Unit" attribute.
Synonym of .pcdata.
Methods Summary
build(name, Type, value[, start, scale, ...])Construct a LIGO Light Weight XML Param document subtree.
Method invoked by document parser when it encounters the end-of-element event.
from_pyvalue(name, value, **kwargs)Convenience wrapper for .build() that constructs a Param element from an instance of a Python builtin type.
getParamsByName(elem, name)Return a list of params with name name under elem.
get_param(xmldoc[, name])Scan xmldoc for a Param named name.
write([fileobj, indent])Recursively write an element and it's children to a file.
Attributes Documentation
- DataUnit¶
The “DataUnit” attribute.
- Name¶
The “Name” attribute.
- Scale¶
The “Scale” attribute.
- Start¶
The “Start” attribute.
- Type¶
The “Type” attribute. Default is “lstring” if not set.
- Unit¶
The “Unit” attribute.
- tagName = 'Param'¶
- validchildren = frozenset({'Comment'})¶
- value¶
Synonym of .pcdata. Makes calling code easier to understand. In the parent class .pcdata is text only. Here it has been translated into a native Python type, but it’s not obvious in calling code that that is what has happened so it can be unclear when reading calling codes if one should be expecting a string or a native value. Using this synonym can clarify the meaning.
Methods Documentation
- classmethod build(name, Type, value, start=None, scale=None, unit=None, dataunit=None, comment=None)¶
Construct a LIGO Light Weight XML Param document subtree. FIXME: document keyword arguments.
- endElement()¶
Method invoked by document parser when it encounters the end-of-element event.
- classmethod from_pyvalue(name, value, **kwargs)¶
Convenience wrapper for .build() that constructs a Param element from an instance of a Python builtin type. See .build() for a description of the valid keyword arguments.
Examples:
>>> import sys >>> # float >>> Param.from_pyvalue("example", 3.0).write(sys.stdout) <Param Name="example:param" Type="real_8">3</Param> >>> # string >>> Param.from_pyvalue("example", "test").write(sys.stdout) <Param Name="example:param" Type="lstring">test</Param> >>> # short string (non-empty data = not NULL) >>> Param.from_pyvalue("example", "").write(sys.stdout) <Param Name="example:param" Type="lstring"> </Param> >>> # None (empty data = NULL) >>> Param.from_pyvalue("example", None).write(sys.stdout) <Param Name="example:param" Type="None"></Param>
Note that any type of Param may be NULL-valued. These examples demonstrate the use of the automatic encoding helper function, which translates None into a None-typed Param because it doesn’t know what else it might be, but, for example, a float-typed Param may also be set to None.
- classmethod getParamsByName(elem, name)¶
Return a list of params with name name under elem.
See also .get_param().
- classmethod get_param(xmldoc, name=None)¶
Scan xmldoc for a Param named name. Raises ValueError if not exactly 1 such Param is found. If name is None (default), then the .paramName attribute of this class is used. The Param class does not provide a .paramName attribute, but sub-classes may choose to.
See also .getParamsByName().
- write(fileobj=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, indent='')¶
Recursively write an element and it’s children to a file.