On this page
  1. string.Formatter
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

string.Formatter

Prev: string.capwords | Up: string | Next: string.Template
Rel: string.capwords, string.Template
Ref: docs.python.org — string.Formatter
Tags: #public #python3 #stdlib #string


Import

import string
from string import Formatter

Signature & Overview

string.Formatter()

string.Formatter class.

Methods & Attributes

Usage

import string

class DefaultFormatter(string.Formatter):
    def get_value(self, key, args, kwargs):
        return kwargs.get(key, f'<{key}>')

assert DefaultFormatter().format('Hi {name} ({role})', name='Ada') == 'Hi Ada (<role>)'

Gotchas

REPL Inspect

from string import Formatter
help(Formatter)

Linked from

Related notes