Skip to content

Instantly share code, notes, and snippets.

@tomoyk
Created December 30, 2018 12:35
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 tomoyk/fd2956e3a97bc77843f1c9ff61e2e98a to your computer and use it in GitHub Desktop.
Save tomoyk/fd2956e3a97bc77843f1c9ff61e2e98a to your computer and use it in GitHub Desktop.
import sys
import re
def main(args):
params = {}
args = (' ' + ' '.join(args)).split(' -')
args = [a for a in args if a] # remove blank elements
for arg in args:
split_arg = arg.split(' ')
key = re.sub('^-*', '', split_arg[0])
val = ' '.join(split_arg[1:])
params[key] = val
print(params)
if __name__ == '__main__':
# main(sys.argv[1:])
main("-e 222 -c foo -t bar --hoge --piyo moge".split(' '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment