<div dir="ltr">Have you tried to put the following line in the top of the file?<br><br><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Source Code Pro';font-size:10.5pt"><span style="color:#808080">#</span> -*- coding: utf-8 -*-<span style="color:#808080"><br></span></pre><br></div><br><div class="gmail_quote"><div dir="ltr">Lauri Kajan <<a href="mailto:lauri.kajan@gmail.com">lauri.kajan@gmail.com</a>> escreveu no dia qui, 22/10/2015 às 08:42:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-size:12.8px">Hi all,</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I'm trying to figure out some encoding problems when using custom python expression functions.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I'm using python functions for defining some label texts. I need use some special characters like ä and ö.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">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.</div><div style="font-size:12.8px">Let the custom function just be</div><div style="font-size:12.8px"><div>@qgsfunction(args='auto', group='Custom')</div><div>def encodingtest(feature, parent):</div><div><span style="white-space:pre-wrap">   </span>return 'ä'</div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">This displays on a map like 'ä'</div><div style="font-size:12.8px">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 'ä'.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">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.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">The only way to resolve this in the code at least that I have found is to use</div><div style="font-size:12.8px">return 'ä'.decode('utf-8')</div><div style="font-size:12.8px">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.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Does anyone else confirm this and have I understood right the problem?</div><div style="font-size:12.8px">Should I file a bug report?</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Thanks,</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">-Lauri</div></div>
_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a></blockquote></div>