[GRASS-dev] [Issue] String formatting issue

Sanjeet edu.sanjeet at gmail.com
Sun Jun 3 17:08:29 PDT 2018


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


More information about the grass-dev mailing list