LSSTApplications
10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
|
A struct to which you can add any fields. More...
Public Member Functions | |
def | __init__ |
Create a Struct with the specified field names and values. More... | |
def | getDict |
Return a dictionary of attribute name: value. More... | |
def | mergeItems |
Copy specified fields from another struct, provided they don't already exist. More... | |
def | copy |
Return a one-level-deep copy (values are not copied) More... | |
def | __eq__ |
def | __len__ |
def | __repr__ |
Private Member Functions | |
def | __safeAdd |
Add a field if it does not already exist and name does not start with __ (two underscores) More... | |
Private Attributes | |
__dict__ | |
A struct to which you can add any fields.
Intended to be used for the return value from Task.run and other Task methods, and useful for any method that returns multiple values.
The intent is to allow accessing returned items by name, instead of unpacking a tuple. This makes the code much more robust and easier to read. It allows one to change what values are returned without inducing mysterious failures: adding items is completely safe, and removing or renaming items causes errors that are caught quickly and reported in a way that is easy to understand.
The primary reason for using Struct instead of dict is that the fields may be accessed as attributes, e.g. aStruct.foo instead of aDict["foo"]. Admittedly this only saves a few characters, but it makes the code significantly more readable.
Struct is preferred over named tuples, because named tuples can be used as ordinary tuples, thus losing all the safety advantages of Struct. In addition, named tuples are clumsy to define and Structs are much more mutable (e.g. one can trivially combine Structs and add additional fields).
def lsst.pipe.base.struct.Struct.__init__ | ( | self, | |
keyArgs | |||
) |
Create a Struct with the specified field names and values.
For example:
[in] | **keyArgs | keyword arguments specifying name=value pairs |
Definition at line 44 of file struct.py.
def lsst.pipe.base.struct.Struct.__eq__ | ( | self, | |
other | |||
) |
def lsst.pipe.base.struct.Struct.__len__ | ( | self | ) |
def lsst.pipe.base.struct.Struct.__repr__ | ( | self | ) |
Definition at line 108 of file struct.py.
|
private |
Add a field if it does not already exist and name does not start with __ (two underscores)
[in] | name | name of field to add |
[in] | val | value of field to add |
RuntimeError | if name already exists or starts with __ (two underscores) |
Definition at line 61 of file struct.py.
def lsst.pipe.base.struct.Struct.copy | ( | self | ) |
Return a one-level-deep copy (values are not copied)
Definition at line 97 of file struct.py.
def lsst.pipe.base.struct.Struct.getDict | ( | self | ) |
Return a dictionary of attribute name: value.
Definition at line 75 of file struct.py.
def lsst.pipe.base.struct.Struct.mergeItems | ( | self, | |
struct, | |||
nameList | |||
) |
Copy specified fields from another struct, provided they don't already exist.
[in] | struct | struct from which to copy |
[in] | *nameList | all remaining arguments are names of items to copy |
For example: foo.copyItems(other, "itemName1", "itemName2") copies other.itemName1 and other.itemName2 into self.
RuntimeError | if any item in nameList already exists in self (but any items before the conflicting item in nameList will have been copied) |
Definition at line 82 of file struct.py.