String concatenation vs. string formatting

Ben Finney ben+python at
Fri Jul 8 19:15:41 EDT 2011

Ben Finney <ben+python at> writes:

>     logger.error(
>         '{0} could not be stored - {1}'.format(
>         (self.preset_file, sys.exc_info()[1]))
> I usually prefer to use named placeholders instead of positional, but
> this duplicates your original.

Ah, I see that the OP *did* use named placeholders. So, even better:

        '{file} could not be stored - {error}'.format(
            file=self.preset_file, error=sys.exc_info()[1]))

 \          “Those who write software only for pay should go hurt some |
  `\                 other field.” —Erik Naggum, in _gnu.misc.discuss_ |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list