How should I provide YARD/RDoc documentation for Ruby keyword arguments?

Should I just continue to use the @param keyword? Yes. YARD recognizes keyword arguments. Use @param to document a single method parameter (either regular or keyword) with a given name, type and optional description: # @param query [String] The search string # @param exact_match [Boolean] whether to do an exact match # @param results_per_page [Integer] … Read more

Python 3.2: How to pass a dictionary into str.format()

This does the job: stats = { ‘copied’: 5, ‘skipped’: 14 } print( ‘Copied: {copied}, Skipped: {skipped}’.format( **stats ) ) #use ** to “unpack” a dictionary For more info please refer to: http://docs.python.org/py3k/library/string.html#format-examples and http://docs.python.org/py3k/tutorial/controlflow.html#keyword-arguments

Add a parameter into kwargs during function call?

For Python versions < 3.5, you need to place the **kwargs variable keyword argument last: f(c=3, **pre_defined_kwargs) See the Calls expression syntax; in all forms of the grammar the “**” expression rule is placed last. In other words, using anything after the **expression syntax is a syntax error. If you want to update the dictionary … Read more

Python: Passing parameters by name along with kwargs

The general idea is: def func(arg1, arg2, …, kwarg1=default, kwarg2=default, …, *args, **kwargs): … You can use as many of those as you want. The * and ** will ‘soak up’ any remaining values not otherwise accounted for. Positional arguments (provided without defaults) can’t be given by keyword, and non-default arguments can’t follow default arguments. … Read more

How do I loop through **kwargs in Python?

For Python 3 users: You can iterate through kwargs with .items() subject = obj.subject body = obj.body for key, value in kwargs.items(): subject = subject.replace(‘[%s]’ % key.toupper(), value) body = body.replace(‘[%s]’ % key.toupper(), value) return (subject, body, obj.is_html) For Python 2 users: You can iterate through kwargs with .iteritems(): subject = obj.subject body = obj.body … Read more