Skip to content

Instantly share code, notes, and snippets.

@ftnext
Created April 14, 2024 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftnext/e5acaca5f49519e65961b6fc97f279f4 to your computer and use it in GitHub Desktop.
Save ftnext/e5acaca5f49519e65961b6fc97f279f4 to your computer and use it in GitHub Desktop.
from optparse import OptionParser, make_option
option_list = [make_option("--no-cache-dir", action="store_true")]
parser = OptionParser(option_list=option_list)
options, args = parser.parse_args(["--no-cache-dir"])
assert options.no_cache_dir
options2, args2 = parser.parse_args(["--no-cache"]) # "--no-cache-d"もOK
assert options2.no_cache_dir
options3, args3 = parser.parse_args([])
assert not options3.no_cache_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment