[GRASS-dev] [Issue] String formatting issue

Maris Nartiss maris.gis at gmail.com
Mon Jun 4 00:58:40 PDT 2018


Hi Sanjeet,
try like this:

msg = _("Bla bla {0} with {1}").format(zero, one)


Māris.


2018-06-04 3:08 GMT+03:00 Sanjeet <edu.sanjeet at gmail.com>:
> Hi everyone,
>
> I came across this type error while porting libs.
>
> msg = _("Module run %s %s ended with error") % (module, code)
> TypeError: %b requires a bytes-like object, or an object that
> implements __bytes__, not 'NoneType'
>
> This uses % format specifier which sometimes fails on Python 3 because
> of strings and bytes differences.
>
> I can resolve this by using fomat() like this:
> msg = _(("Module run {} {} ended with error").format(module,code))
>
> Do you think this is a good way to resolve this?
> Is "format()" going to work well with translations using the
> ''gettext()'' used as _() as shown in the above line?
>
> Thanks,
> Sanjeet
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-dev


More information about the grass-dev mailing list