Last active
November 10, 2023 06:07
-
-
Save wassname/f1c23636cc04b39176bd82f45c6e398a to your computer and use it in GitHub Desktop.
argparse in jupyter?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
sometimes you want to run or adapt a cli script from jupyter, here a decent way to do it | |
""" | |
argvs = """ | |
--rank 16 | |
--context=128 | |
--vae_context=64 | |
""" | |
argvs = argvs.replace('\n', ' ').strip() | |
argv = [s.strip() for s in argvs.split(" ") if s and not s.startswith("#")] | |
print(argv) | |
args = parser.parse_args(argv) | |
args | |
args = parser.parse_args(argv) | |
args | |
# or using a argparse Namespace | |
from argparse import Namespace | |
Namespace(a=1) | |
# another way with no args is | |
args = parser.parse_known_args()[0] | |
args.__dict__['a']=1 # an any positional args | |
# a better way might be to use https://pypi.org/project/simple-parsing/ where you can just insansiate the options classe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment