[Qgis-developer] Unicode type QGIS_RELEASE_NAME and QGIS_VERSION
Matthias Kuhn
matthias at opengis.ch
Tue Jul 12 00:35:27 PDT 2016
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
More information about the Qgis-developer
mailing list