[ckan-dev] " '%s' % thing " vs " '{0}'.format(thing) "
Toby Dacre
toby.okfn at gmail.com
Tue Jan 8 02:28:55 UTC 2013
Sounds like .format() is the winner and we should generally be using it for
new code
On 7 January 2013 13:13, Adrià Mercader <adria.mercader at okfn.org> wrote:
> 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
>
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20130108/3bc471ec/attachment-0001.html>
More information about the ckan-dev
mailing list