def format(self, string): """format string and return html""" kwargs = dict() for key in format_keys.keys(string): value = getattr(self, key, None) kwargs[key] = value if value else "" return string.format(**kwargs)
def format(self, string): """format string""" kwargs = dict() for key in format_keys.keys(string): value = getattr(self, key, None) if value is None: value = "" kwargs[key] = value return string.format(**kwargs).replace(" ", "%20")
#!/usr/bin/env python import format_keys string = "https://api.travis-ci.org/{fullname}.svg?branch={branch}" keys = format_keys.keys(string) print(keys)