Skip to content

Instantly share code, notes, and snippets.

@gone
Created November 21, 2011 20:55
Show Gist options
  • Save gone/1383899 to your computer and use it in GitHub Desktop.
Save gone/1383899 to your computer and use it in GitHub Desktop.
option 1:
url_dicts, url_args = url_check.groupdict(), url_check.groups()
if url_dicts:
do_thing(**url_dicts)
else:
do_thing(*url_args)
option 2:
url_arguments = url_check.groupdict() or url_check.groups()
if isinstance(url_arguments, dict):
do_thing(**url_arguments)
else:
do_thing(*url_arguments)
@j2labs
Copy link

j2labs commented Nov 21, 2011

My mental ordering always thinks of args before kwargs, due to how they're used in functions.

url_args, url_dicts = url_check.groups(), url_check.groupdict()
if url_args:
    do_thing(*url_args)
else:
    do_thing(**url_dicts)

@gone
Copy link
Author

gone commented Nov 21, 2011

Current

if not hasattr(self, '_url_args') or self._url_args is None:
                self._url_args = []

            rendered = fun(*self._url_args)

changes to

         if not hasattr(self, '_url_args') or self._url_args is None:
                self._url_args = []
            if isinstance(self._url_args, dict):
                rendered = fun(**self._url_args)
            else:
                rendered = fun(*self._url_args)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment