gAttr(cdf_file, attr_name, create=False)¶
Global Attribute for a CDF
Normally accessed by providing a key to a
>>> attribute = cdffile.attrs['attribute_name'] >>> first_gentry = attribute
Each element of the list is a single gEntry of the appropriate type. The index to the elements is the gEntry number.
A gEntry may be either a single string or a 1D array of numerical type. Entries of numerical type (everything but CDF_CHAR and CDF_UCHAR) with a single element are returned as scalars; multiple-element entries are returned as a list. No provision is made for accessing below the entry level; the whole list is returned at once (but Python’s slicing syntax can be used to extract individual items from that list.)
Multi-dimensional slicing is not supported; an entry with multiple elements will have all elements returned (and can thus be sliced itself). Example:
>>> first_three = attribute[5, 0:3] #will fail >>> first_three = attribute[0:3] #first three elements of 5th Entry
gEntries are not necessarily contiguous; a gAttribute may have an entry 0 and entry 2 without an entry 1.
len()will return the number of gEntries; use
max_idx()to find the highest defined gEntry number and
has_entry()to determine if a particular gEntry number exists. Iterating over all entries is also supported:
>>> entrylist = [entry for entry in attribute]
Deleting gEntries will leave a “hole”:
>>> attribute[0:3] = [1, 2, 3] >>> del attribute >>> attribute.has_entry(1) False >>> attribute.has_entry(2) True >>> print attribute[0:3] [1, None, 3]
Multi-element slices over nonexistent gEntries will return
Nonewhere no entry exists. Single-element indices for nonexistent gEntries will raise
Noneto a gEntry will delete it.
When assigning to a gEntry, the type is chosen to match the data; subject to that constraint, it will try to match (in order):
existing gEntry of the same number in this gAttribute
other gEntries in this gAttribute
data-matching constraints described in