Is there a way to use the click library in a cell in a Jupyter laptop? I would like to pass the checkboxes into my Jupyter laptop code, in notepad, to make it more smooth transition to a stand-alone script. For example, using OptionParser from a Jupyter laptop cell:
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()
Exit: options: {'fake': 'False'} args: ['True - help'] Fake detected
Using the click library, I get an error string. I ran this code from Jupyter's laptop cell:
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()
Output (Truncated):
UnsupportedOperation Traceback (most recent call last)
<ipython-input-6-ad31be7bf0fe> in <module>()
12 if __name__ == '__main__':
13 sys.argv = ['--count', '3']
---> 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`."""
--> 722 return self.main(*args, **kwargs)
723
724
...
257
258 if message:
--> 259 file.write(message)
260 file.flush()
261
UnsupportedOperation: not writable
source
share