astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v0.3 »
- Astropy Core Package Utilities (`astropy.utils`) »
- ProgressBar

# ProgressBar

class `astropy.utils.console.``ProgressBar`(total_or_items, file=None)

  Bases: `astropy.extern.six.Iterator`

  A class to display a progress bar in the terminal.

  It is designed to be used either with the `with` statement:

      with ProgressBar(len(items)) as bar:
          for item in enumerate(items):
              bar.update()

  or as a generator:

      for item in ProgressBar(items):
          item.process()

  Methods Summary

  `iterate`(*args, **kwargs) | Deprecated since version 0.3.
  `map`(function, items[, multiprocess, file]) | Does a `map` operation while displaying a progress bar with percentage complete.
  `update`([value]) | Update the progress bar to the given value (out of the total given to the constructor).

  Methods Documentation

  classmethod `iterate`(*args, **kwargs)

    Deprecated since version 0.3: Use ProgressBar instead.

    Iterate over a sequence while indicating progress with a progress bar in the terminal.

        for item in ProgressBar.iterate(items):
            pass

    Parameters:

    items : sequence

    > A sequence of items to iterate over

    file : writeable file-like object, optional

    > The file to write the progress bar to. Defaults to `sys.stdout`. If `file` is not a tty (as determined by calling its `isatty` member, if any), the scrollbar will be completely silent.

    Returns:

    generator : :

    > A generator over `items`

  classmethod `map`(function, items, multiprocess=False, file=None)

    Does a `map` operation while displaying a progress bar with percentage complete.

        def work(i):
            print(i)

        ProgressBar.map(work, range(50))

    Parameters:

    function : function

    > Function to call for each step

    items : sequence

    > Sequence where each element is a tuple of arguments to pass to function.

    multiprocess : bool, optional

    > If `True`, use the `multiprocessing` module to distribute each task to a different processor core.

    file : writeable file-like object, optional

    > The file to write the progress bar to. Defaults to `sys.stdout`. If `file` is not a tty (as determined by calling its `isatty` member, if any), the scrollbar will be completely silent.

  `update`(value=None)

    Update the progress bar to the given value (out of the total given to the constructor).