[ckan-dev] " '%s' % thing " vs " '{0}'.format(thing) "

Adrià Mercader adria.mercader at okfn.org
Mon Jan 7 13:13:26 UTC 2013


I've been favouring .format() also (It took me a while, I had %s
hardcoded on my brain). It's a little more verbose but more readable,
and %s is definitely deprecated on latest versions of python 3, even
though still supported.
Probably not the end of the world if we use %s in some short strings though

Adrià

On 7 January 2013 10:04, Sean Hammond <sean.hammond at okfn.org> wrote:
>> 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
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev




More information about the ckan-dev mailing list