Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- 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()
- 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
Add Comment
Please, Sign In to add comment