Last active
May 10, 2016 09:59
-
-
Save sanfx/7037550 to your computer and use it in GitHub Desktop.
mock argparse's Namespace behaviour.
This file contains hidden or 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
class Namespace(object): | |
"""Mock for argparse's NameSpace | |
""" | |
def __init__(self, lst=None, flter=None): | |
super(Namespace, self).__init__() | |
self.filter = flter | |
self.lst = lst | |
def __repr__(self): | |
return 'Namespace(filter=self.filter, lst = self.lst)' | |
args = Namespace(lst='["Hi","By"]', flter='B') | |
print args, type(args), args.lst, args.filter | |
# a better way | |
import collections | |
MockNamespace = collections.namedtuple("MockNamespace", ["fltr"]) | |
MockNamespace('some/path') | |
# will resultMockNamespace(fltr='some/path') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dang, namedtuple is what I was looking for. Thanks!