

def format(text, *args, **kw):
    '\n    Format a string using the string formatting operator and/or :func:`str.format()`.\n\n    :param text: The text to format (a string).\n    :param args: Any positional arguments are interpolated into the text using\n                 the string formatting operator (``%``). If no positional\n                 arguments are given no interpolation is done.\n    :param kw: Any keyword arguments are interpolated into the text using the\n               :func:`str.format()` function. If no keyword arguments are given\n               no interpolation is done.\n    :returns: The text with any positional and/or keyword arguments\n              interpolated (a string).\n\n    The implementation of this function is so trivial that it seems silly to\n    even bother writing and documenting it. Justifying this requires some\n    context :-).\n\n    **Why format() instead of the string formatting operator?**\n\n    For really simple string interpolation Python\'s string formatting operator\n    is ideal, but it does have some strange quirks:\n\n    - When you switch from interpolating a single value to interpolating\n      multiple values you have to wrap them in tuple syntax. Because\n      :func:`format()` takes a `variable number of arguments`_ it always\n      receives a tuple (which saves me a context switch :-). Here\'s an\n      example:\n\n      >>> from humanfriendly.text import format\n      >>> # The string formatting operator.\n      >>> print(\'the magic number is %s\' % 42)\n      the magic number is 42\n      >>> print(\'the magic numbers are %s and %s\' % (12, 42))\n      the magic numbers are 12 and 42\n      >>> # The format() function.\n      >>> print(format(\'the magic number is %s\', 42))\n      the magic number is 42\n      >>> print(format(\'the magic numbers are %s and %s\', 12, 42))\n      the magic numbers are 12 and 42\n\n    - When you interpolate a single value and someone accidentally passes in a\n      tuple your code raises a :exc:`~exceptions.TypeError`. Because\n      :func:`format()` takes a `variable number of arguments`_ it always\n      receives a tuple so this can never happen. Here\'s an example:\n\n      >>> # How expecting to interpolate a single value can fail.\n      >>> value = (12, 42)\n      >>> print(\'the magic value is %s\' % value)\n      Traceback (most recent call last):\n        File "<stdin>", line 1, in <module>\n      TypeError: not all arguments converted during string formatting\n      >>> # The following line works as intended, no surprises here!\n      >>> print(format(\'the magic value is %s\', value))\n      the magic value is (12, 42)\n\n    **Why format() instead of the str.format() method?**\n\n    When you\'re doing complex string interpolation the :func:`str.format()`\n    function results in more readable code, however I frequently find myself\n    adding parentheses to force evaluation order. The :func:`format()` function\n    avoids this because of the relative priority between the comma and dot\n    operators. Here\'s an example:\n\n    >>> "{adjective} example" + " " + "(can\'t think of anything less {adjective})".format(adjective=\'silly\')\n    "{adjective} example (can\'t think of anything less silly)"\n    >>> ("{adjective} example" + " " + "(can\'t think of anything less {adjective})").format(adjective=\'silly\')\n    "silly example (can\'t think of anything less silly)"\n    >>> format("{adjective} example" + " " + "(can\'t think of anything less {adjective})", adjective=\'silly\')\n    "silly example (can\'t think of anything less silly)"\n\n    The :func:`compact()` and :func:`dedent()` functions are wrappers that\n    combine :func:`format()` with whitespace manipulation to make it easy to\n    write nice to read Python code.\n\n    .. _variable number of arguments: https://docs.python.org/2/tutorial/controlflow.html#arbitrary-argument-lists\n    '
    if args:
        text %= args
    if kw:
        text = text.format(**text)
    return text

dataset/ETHPy150Open xolox/python-humanfriendly/humanfriendly/text.py format/VarMisuse@40/1498 `kw`->`text`