[GRASS-dev] g.message and unicode in python
Nikos Alexandris
nik at nikosalexandris.net
Fri Nov 21 10:46:21 PST 2014
On 21.11.2014 20:17, Glynn Clements wrote:
> Nikos Alexandris wrote:
>
>> How can I print an informational message, using g.message, that
>> contains unicode stuff via python (2.x)?
>>
>> For example, how do I correctly translate this command
>>
>> g.message message="ρ(p) = π x L(λ) x d^2 / ESUN(λ) x cos(θ(S))"
>>
>> (it contains the greek r (ρ, pronounced rho) and pi (π, pronounced
>> pe)
>>
>> to work in a python script?
> In general, you can't assume that the terminal is capable of
> displaying those characters.
True. Working on Funtoo here, which has utf-8 pre-set.
> If they are representable in the current locale, then
>
> encoding = locale.getdefaultlocale()[1]
> grass.message(msg.encode(encoding))
>
> should pass the correct bytes.
I will try this to understand how it works.
> If they aren't representable, then the .encode() method will raise a
> UnicodeEncodeError.
>
> If a UTF-8 locale is being used, any Unicode string can be converted,
> but that doesn't mean that the characters will display correctly; if
> the font lacks those characters, they'll just show as "?" or "~" or a
> box with the hex code or similar.
So, it's bad idea even trying to do this (and thinking that everyone is
going to read it)? Best practice to avoid such situations alltogether
and respect the cross-platform principle?
Thank you, Nikos
More information about the grass-dev
mailing list