Created
December 30, 2018 12:35
-
-
Save tomoyk/fd2956e3a97bc77843f1c9ff61e2e98a to your computer and use it in GitHub Desktop.
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
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