[Qgis-developer] Unicode type QGIS_RELEASE_NAME and QGIS_VERSION

Akbar Gumbira akbargumbira at gmail.com
Tue Jul 12 00:59:01 PDT 2016


>
> As a general rule of thumb: don't cast to other types if there is no
> requirement, that will help to prevent such issues and make the upcoming
> upgrade to python 3 much easier.

Yes, this should be Python 2.xx's developer haiku: *Bytes on the outside,
unicode on the inside. Encode/decode at the edges. *It's a bad habit in
Python 2.xx to cast to str when the string probably could contain accented
chars (e.g doing *str(layer.source()*). But in Python 3, str is unicode,
most of problem would probably be gone. For some strategies, perhaps what
we did in InaSAFE could be useful, see the 3rd comment in this PR:
https://github.com/inasafe/inasafe/pull/1674

On Tue, Jul 12, 2016 at 9:35 AM, Matthias Kuhn <matthias at opengis.ch> wrote:

> Hi Minoru
>
> On 07/12/2016 03:01 AM, Minoru Akagi wrote:
> > Hi,
> >
> > Just a quick note for python plugin devs.
> >
> > I received an error report related to QGis.QGIS_VERSION constant [1].
> > In QGIS 2.16, QGis.GIS_RELEASE_NAME and QGis.QGIS_VERSION constants
> > have been changed to unicode type. I guess that the change is
> > necessary for unicode release name support.
>
> I don't think the type has changed. Before python just converted it
> silently because the conversion of a pure ascii unicode string was trivial.
> Compare:
>
> >>> str(u'Essen')
> 'Essen'
> >>> str(u'Nødebo')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xf8' in
> position 1: ordinal not in range(128)
>
> As a general rule of thumb: don't cast to other types if there is no
> requirement, that will help to prevent such issues and make the upcoming
> upgrade to python 3 much easier.
>
> Matthias
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>



-- 

*-------------------*
*Akbar Gumbira *
*www.akbargumbira.com <http://www.akbargumbira.com>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160712/acb4e49d/attachment.html>


More information about the Qgis-developer mailing list