Returns a resettable iterable object. In this context, resettable means that when :meth:`object.__iter__` is called, the iterable returned always points to the first element in the sequence, similar to how the list and tuple behave. Args: wrfseq (iterable): An iterable typ
(wrfseq)
| 373 | |
| 374 | |
| 375 | def get_iterable(wrfseq): |
| 376 | """Returns a resettable iterable object. |
| 377 | |
| 378 | In this context, resettable means that when :meth:`object.__iter__` |
| 379 | is called, the iterable returned always points to the first element |
| 380 | in the sequence, similar to how the list and tuple behave. |
| 381 | |
| 382 | Args: |
| 383 | |
| 384 | wrfseq (iterable): An iterable type, which includes lists, tuples, |
| 385 | dictionaries, generators, and user-defined classes. |
| 386 | |
| 387 | Returns: |
| 388 | |
| 389 | iterable: A resettable iterator object. |
| 390 | |
| 391 | """ |
| 392 | if not is_multi_file(wrfseq): |
| 393 | return wrfseq |
| 394 | else: |
| 395 | if not is_mapping(wrfseq): |
| 396 | |
| 397 | if isinstance(wrfseq, (list, tuple, IterWrapper)): |
| 398 | return wrfseq |
| 399 | else: |
| 400 | return IterWrapper(wrfseq) # generator/custom iterable class |
| 401 | |
| 402 | else: |
| 403 | if isinstance(wrfseq, dict): |
| 404 | return wrfseq |
| 405 | else: |
| 406 | return dict(wrfseq) # generator/custom iterable dict class |
| 407 | |
| 408 | |
| 409 | # Helper to extract masked arrays from DataArrays that convert to NaN |