
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/plot_7_sys_argv.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_auto_examples_plot_7_sys_argv.py>`
        to download the full example code or to run this example in your browser via Binder

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_plot_7_sys_argv.py:


Using ``sys.argv`` in examples
==============================

This example demonstrates the use of ``sys.argv`` in example ``.py`` files.

By default, all example ``.py`` files will be run by Sphinx-Gallery **without** any
arguments. Notice below that ``sys.argv`` is a list consisting of only the
file name. Further, any arguments added will take on the default value.

This behavior can be changed by using the `reset_argv` option in the sphinx configuration, see :ref:`reset_argv`.

.. GENERATED FROM PYTHON SOURCE LINES 14-23




.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none

    sys.argv: ['/build/sphinx-gallery-DaI3lO/sphinx-gallery-0.10.1/examples/plot_7_sys_argv.py']
    parsed args: Namespace(option='default')






|

.. code-block:: python3


    import argparse
    import sys

    parser = argparse.ArgumentParser(description='Toy parser')
    parser.add_argument('--option', default='default',
                        help='a dummy optional argument')
    print('sys.argv:', sys.argv)
    print('parsed args:', parser.parse_args())

**Estimated memory usage:**  9 MB


.. _sphx_glr_download_auto_examples_plot_7_sys_argv.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example


  .. container:: binder-badge

    .. image:: images/binder_badge_logo.svg
      :target: https://mybinder.org/v2/gh/sphinx-gallery/sphinx-gallery.github.io/master?urlpath=lab/tree/notebooks/auto_examples/plot_7_sys_argv.ipynb
      :alt: Launch binder
      :width: 150 px


  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: plot_7_sys_argv.py <plot_7_sys_argv.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: plot_7_sys_argv.ipynb <plot_7_sys_argv.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
