From 7a60f336990e6cc69caeb7fb7467f01052c03e8a 2010-01-05 08:02:45 From: Fernando Perez Date: 2010-01-05 08:02:45 Subject: [PATCH] Small improvements to argparse. I've submitted these fixes upstream, let's hope they get included: http://groups.google.com/group/argparse-devs/browse_thread/thread/2c03e4b3d28a3203 --- diff --git a/IPython/external/argparse.py b/IPython/external/argparse.py index 8b96e62..5786b50 100644 --- a/IPython/external/argparse.py +++ b/IPython/external/argparse.py @@ -1169,8 +1169,7 @@ class Namespace(_AttributeHolder): """ def __init__(self, **kwargs): - for name in kwargs: - setattr(self, name, kwargs[name]) + self.__dict__.update(**kwargs) def __eq__(self, other): return vars(self) == vars(other) @@ -1178,6 +1177,9 @@ class Namespace(_AttributeHolder): def __ne__(self, other): return not (self == other) + def __contains__(self, key): + return key in self.__dict__ + class _ActionsContainer(object): @@ -2288,9 +2290,13 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): # Help-printing methods # ===================== def print_usage(self, file=None): + if file is None: + file = _sys.stdout self._print_message(self.format_usage(), file) def print_help(self, file=None): + if file is None: + file = _sys.stdout self._print_message(self.format_help(), file) def print_version(self, file=None):