Ah... I think I now understand what you are saying. You are saying that expression files are always saved in your system default encoding system.
Sorry for the noise. Lauri Kajan <[email protected]> escreveu no dia qui, 22/10/2015 às 13:25: > Hi Alexandre, > > The u'ä' works if I tell the file encoding using your snippet > > # -*- coding: utf-8 -*- > > But this works only in qgis and is not a correct way. > I cannot then debug my function in any IDE cause the file is encoded > differently than it says. > > -Lauri > > On Thu, Oct 22, 2015 at 1:37 PM, Alexandre Neto <[email protected]> > wrote: > >> Have you tried to put the following line in the top of the file? >> >> # -*- coding: utf-8 -*- >> >> >> >> Lauri Kajan <[email protected]> escreveu no dia qui, 22/10/2015 às >> 08:42: >> >>> Hi all, >>> >>> I'm trying to figure out some encoding problems when using custom python >>> expression functions. >>> >>> I'm using python functions for defining some label texts. I need use >>> some special characters like ä and ö. >>> >>> When a new file is created in function editor the file is encoded in my >>> system encoding cp1252. At least the ä is coded to 0xe4 if I check that >>> with hex-editor. >>> Let the custom function just be >>> @qgsfunction(args='auto', group='Custom') >>> def encodingtest(feature, parent): >>> return 'ä' >>> >>> This displays on a map like 'ä' >>> It seems that the file is converted to utf-8 before execution and the ä >>> is then coded to 0xc3 0xa4. Now QGIS still tries to interpret this as >>> cp1252 and then displays this as 'ä'. >>> >>> It doesn't help to define the ä as unicode like u'ä' because QGIS still >>> sees the ä as 0xc3 0xa4 and think that it is in cp1252. >>> >>> The only way to resolve this in the code at least that I have found is >>> to use >>> return 'ä'.decode('utf-8') >>> This works on QGIS but the file can't be executed elsewhere (IDE) since >>> the file is truly in cp1252 and 0xe4 can't be decoded using utf-8. >>> >>> >>> Does anyone else confirm this and have I understood right the problem? >>> Should I file a bug report? >>> >>> >>> Thanks, >>> >>> -Lauri >>> _______________________________________________ >>> Qgis-developer mailing list >>> [email protected] >>> http://lists.osgeo.org/mailman/listinfo/qgis-developer >> >> > _______________________________________________ > Qgis-developer mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________ Qgis-developer mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/qgis-developer
