### Navigation

- index
- modules |
- modules |
- next |
- previous |
- homepage|
- search|
- documentation »
- datamodel - easy to use general data model »

# spacepy.datamodel.SpaceData

class `spacepy.datamodel.``SpaceData`(*args, **kwargs)

  Datamodel class extending dict by adding attributes.

  `flatten`() | Method to collapse datamodel to one level deep
  `tree`(**kwargs) | Print the contents of the SpaceData object in a visual tree

  `flatten`()

    Method to collapse datamodel to one level deep

    Examples

        >>> import spacepy.datamodel as dm
        >>> import spacepy.toolbox as tb
        >>> a = dm.SpaceData()
        >>> a['1'] = dm.SpaceData(dog = 5, pig = dm.SpaceData(fish=dm.SpaceData(a='carp', b='perch')))
        >>> a['4'] = dm.SpaceData(cat = 'kitty')
        >>> a['5'] = 4
        >>> a.tree()
        +
        |____1
             |____dog
             |____pig
                  |____fish
                       |____a
                       |____b
        |____4
             |____cat
        |____5

        >>> b = dm.flatten(a)
        >>> b.tree()
        +
        |____1<--dog
        |____1<--pig<--fish<--a
        |____1<--pig<--fish<--b
        |____4<--cat
        |____5

        >>> a.flatten()
        >>> a.tree()
        +
        |____1<--dog
        |____1<--pig<--fish<--a
        |____1<--pig<--fish<--b
        |____4<--cat
        |____5

  `tree`(**kwargs)

    Print the contents of the SpaceData object in a visual tree

    Other Parameters:
    | verbose : boolean (optional) print more info spaces : string (optional) string will added for every line levels : integer (optional) number of levels to recurse through (True means all) attrs : boolean (optional) display information for attributes

    See also

    `toolbox.dictree`

    Examples

        >>> import spacepy.datamodel as dm
        >>> import spacepy.toolbox as tb
        >>> a = dm.SpaceData()
        >>> a['1'] = dm.SpaceData(dog = 5)
        >>> a['4'] = dm.SpaceData(cat = 'kitty')
        >>> a['5'] = 4
        >>> a.tree()
        +
        |____1
             |____dog
        |____4
             |____cat
        |____5

### Navigation

- index
- modules |
- modules |
- next |
- previous |
- homepage|
- search|
- documentation »
- datamodel - easy to use general data model »