-
-
Save eegilbert/662a08cf11b64ba5b591359806b1c2ef to your computer and use it in GitHub Desktop.
Flag per function - Argparse
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 argparse | |
class c1(object): | |
def cleanup(self): | |
print 'c1' | |
class c2(object): | |
def cleanup(self): | |
print 'c2' | |
class c3(object): | |
def cleanup(self): | |
print 'c3' | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-1', const=c1, dest='cleaners', action='append_const') | |
parser.add_argument('-2', const=c2, dest='cleaners', action='append_const') | |
parser.add_argument('-3', const=c3, dest='cleaners', action='append_const') | |
args = parser.parse_args() | |
if args.cleaners is not None: | |
for cleaner_class in args.cleaners: | |
cleaner = cleaner_class() | |
cleaner.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment