title: Using click library in jupyter notebook cell
body: <p>Is there a way to use the click library in a Jupyter notebook cell?
  I would like to pass flags to my Jupyter notebook code, within the notebook, to
  make it smoother transiting to a stand alone script. For instance, using
  OptionParser from a Jupyter notebook cell:</p>
  
  <pre><code>from optparse import OptionParser
  import sys
  
  
  def main():
      parser = OptionParser()
      parser.add_option('-f', '--fake',
                      default='False',
                  help='Fake data')
      (options,args) = parser.parse_args()
      print('options:{} args: {}'.format(options, args))
      if options.fake:
          print('Fake detected')
  
  def test_args():
  
      print('hello')
  
  if __name__ == '__main__':
  
      sys.argv = ['--fake', 'True' '--help']
      main()
  </code></pre>
  
  <p>output:
      options:{'fake': 'False'} args: ['True--help']
      Fake detected</p>
  
  <p>Using the click library, I get a string of errors. I ran this code from a
  Jupyter notebook cell:</p>
  
  <pre><code>import click
  
  @click.command()
  @click.option('--count', default=1, help='Number of greetings.')
  @click.option('--name', prompt='Your name',
              help='The person to greet.')
  def hello(count, name):
      """Simple program that greets NAME for a total of COUNT times."""
      for x in range(count):
          click.echo('Hello %s!' % name)
  
  if __name__ == '__main__':
      hello()
  </code></pre>
  
  <p>Ouput (truncated):</p>
  
  <pre><code>UnsupportedOperation                      Traceback (most recent call last)
  &lt;ipython-input-6-ad31be7bf0fe&gt; in &lt;module&gt;()
      12 if __name__ == '__main__':
      13     sys.argv = ['--count', '3']
  ---&gt; 14     hello()
  
  ~/.local/lib/python3.6/site-packages/click/core.py in __call__(self, *args, **kwargs)
      720     def __call__(self, *args, **kwargs):
      721         """Alias for :meth:`main`."""
  --&gt; 722         return self.main(*args, **kwargs)
      723 
      724 
  ...
  257 
      258     if message:
  --&gt; 259         file.write(message)
      260     file.flush()
      261 
  
  UnsupportedOperation: not writable
  </code></pre>