Guest User

Untitled

a guest
Dec 14th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. from optparse import OptionParser
  2. import sys
  3.  
  4.  
  5. def main():
  6. parser = OptionParser()
  7. parser.add_option('-f', '--fake',
  8. default='False',
  9. help='Fake data')
  10. (options,args) = parser.parse_args()
  11. print('options:{} args: {}'.format(options, args))
  12. if options.fake:
  13. print('Fake detected')
  14.  
  15. def test_args():
  16.  
  17. print('hello')
  18.  
  19. if __name__ == '__main__':
  20.  
  21. sys.argv = ['--fake', 'True' '--help']
  22. main()
  23.  
  24. import click
  25.  
  26. @click.command()
  27. @click.option('--count', default=1, help='Number of greetings.')
  28. @click.option('--name', prompt='Your name',
  29. help='The person to greet.')
  30. def hello(count, name):
  31. """Simple program that greets NAME for a total of COUNT times."""
  32. for x in range(count):
  33. click.echo('Hello %s!' % name)
  34.  
  35. if __name__ == '__main__':
  36. hello()
  37.  
  38. UnsupportedOperation Traceback (most recent call last)
  39. <ipython-input-6-ad31be7bf0fe> in <module>()
  40. 12 if __name__ == '__main__':
  41. 13 sys.argv = ['--count', '3']
  42. ---> 14 hello()
  43.  
  44. ~/.local/lib/python3.6/site-packages/click/core.py in __call__(self, *args, **kwargs)
  45. 720 def __call__(self, *args, **kwargs):
  46. 721 """Alias for :meth:`main`."""
  47. --> 722 return self.main(*args, **kwargs)
  48. 723
  49. 724
  50. ...
  51. 257
  52. 258 if message:
  53. --> 259 file.write(message)
  54. 260 file.flush()
  55. 261
  56.  
  57. UnsupportedOperation: not writable
Add Comment
Please, Sign In to add comment