[ckan-dev] " '%s' % thing " vs " '{0}'.format(thing) "
Sean Hammond
sean.hammond at okfn.org
Mon Jan 7 10:04:28 UTC 2013
> Whilst it is vital to be using the _('...').format(...) for translatable
> content using more than 1 parameter to allow positional changes and as such
> probably best to use this even if a single parameter so that if more are
> added then broken code is less likely to be left incorrect.
>
> However for non-translatable content I find the % syntax to be more
> compact/readable
>
> Is it just me who cares about this or should we try to have a single
> approach?
I actually thought %s was gone in Python 3 which is why I was using
.format() everywhere, but googling it looks like %s is still in Python
3?
I still prefer .format() everywhere just for consistency, then we're
less likely to forget to use it for some translatable strings, but I'm
happy to relax the 'rule' and say format only has to be used for i18n
strings if you prefer.
format() has other advantages like can make code more explicit and
readable if you give names to the format-specifiers (which also helps
translators with i18n strings), and can do some things that %s can't
More information about the ckan-dev
mailing list