@@ -186,7 +186,9 @@ However, for most operations on attributes, it is much easier to use the ``.aval
186186property instead. This accesses *the same attributes *, but in the form of a simple
187187"name: value" dictionary.
188188
189- Thus for example, to fetch an attribute you would usually write just :
189+ Get attribute value
190+ ^^^^^^^^^^^^^^^^^^^
191+ For example, to fetch an attribute you would usually write just :
190192
191193.. testsetup ::
192194
@@ -205,23 +207,15 @@ and **not** :
205207
206208.. doctest :: python
207209
208- >>> # WRONG: this reads an NcAttribute, not its value
210+ >>> # WRONG: this get the NcAttribute object , not its value
209211 >>> unit = dataset.variables[" x" ].attributes[" units" ]
210212
211- or:
212-
213- .. doctest :: python
214-
215- >>> # WRONG: this gets NcAttribute.value as a character array, not a string
213+ >>> # WRONG: this returns a character array, not a string
216214 >>> unit = dataset.variables[" x" ].attributes[" units" ].value
217215
218- or even (which is at least correct):
219-
220- .. doctest :: python
221-
222- >>> unit = dataset.variables[" x" ].attributes[" units" ].as_python_value()
223-
224216
217+ Set attribute value
218+ ^^^^^^^^^^^^^^^^^^^
225219Likewise, to **set ** a value, you would normally just
226220
227221.. doctest :: python
@@ -236,9 +230,11 @@ and **not**
236230 >>> dataset.variables[" x" ].attributes[" units" ].value = " K"
237231
238232
239- Note also, that as the ``.avals `` is a dictionary, you can use standard dictionary
240- methods such as ``update `` and ``get `` to perform other operations in a relatively
241- natural, Pythonic way.
233+ ``.avals `` as a dictionary
234+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
235+ Note also, that as ``.avals `` is a dictionary, you can use standard dictionary
236+ methods such as ``pop ``, ``update `` and ``get `` to perform other operations in a
237+ relatively natural, Pythonic way.
242238
243239.. doctest :: python
244240
@@ -247,6 +243,12 @@ natural, Pythonic way.
247243
248244 >>> dataset.attributes.update({" experiment" : " A407" , " expt_run" : 704 })
249245
246+ .. note ::
247+ The new ``.avals `` property effectively replaces the old
248+ :meth: `~ncdata.NcData.get_attrval ` and :meth: `~ncdata.NcData.set_attrval ` methods,
249+ which are now deprecated and will eventually be removed.
250+
251+
250252.. _data-constructors :
251253
252254Core Object Constructors
0 commit comments