[GRASS-dev] [Issue] String formatting issue

Nikos Alexandris nik at nikosalexandris.net
Mon Jun 4 02:54:11 PDT 2018

* Sanjeet <edu.sanjeet at gmail.com> [2018-06-03 18:08:29 -0600]:

>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?

Normally everyone would want to follow the "new" style of formatting
strings, which offers many more options. Why stick to the old style,
i.e. using the % notation?

Cheers, Nikos
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20180604/271cf4d4/attachment.sig>

More information about the grass-dev mailing list