class GribMessage
#A GRIB message.
#Each ``GribMessage`` is stored as a key/value pair in a dictionary-like
#structure. It can be used in a context manager or by itself. When the
#``GribFile`` it belongs to is closed, the ``GribFile`` closes any open
#``GribMessage``s that belong to it. If a ``GribMessage`` is closed before
#its ``GribFile`` is closed, it informs the ``GribFile`` of its closure.
#Scalar and vector values are set appropriately through the same method.
#``GribMessage``s can be instantiated from a ``GribFile``, cloned from
#other ``GribMessage``s or taken from samples. Iterating over the members
#of a ``GribFile`` extracts the ``GribMessage``s it contains until the
#``GribFile`` is exhausted.
#Usage::
>>> with GribFile(filename) as grib:
... # Access a key from each message
... for msg in grib:
... print(msg[key_name])
... # Report number of keys in message
... len(msg)
... # Report message size in bytes
... msg.size
... # Report keys in message
... msg.keys()
... # Set scalar value
... msg[scalar_key] = 5
... # Check key's value
... msg[scalar_key]
... msg[key_name]
... # Array values are set transparently
... msg[array_key] = [1, 2, 3]
... # Messages can be written to file
... with open(testfile, "w") as test:
... msg.write(test)
... # Messages can be cloned from other messages
... msg2 = GribMessage(clone=msg)
... # If desired, messages can be closed manually or used in with
... msg.close() |