Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

How do I print unicode in variables?

If you have a question or need help, this is the place to be.
Post Reply
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

How do I print unicode in variables?

Post by Mastiff »

I know the correct way of printing unicode strings:

Code: Select all

print(u'├ª├©├Ñ')
But how do I print unicode variables? So:

Code: Select all

testvariable='├©├ª├Ñ'
print(testvariable)
This gives me:

Code: Select all

12:02:20      ├â┬©├â┬ª├â┬Ñ
So how do I use the unicode marker with variables?
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: How do I print unicode in variables?

Post by Pako »

Properly it should be as follows:

Code: Select all

testvariable = u'├©├ª├Ñ'
print testvariable
If the variable is not a unicode string, then it could be like this:

Code: Select all

print testvariable.decode(eg.systemEncoding)
Pako
You know flattr ? You can Image
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: How do I print unicode in variables?

Post by Mastiff »

Thanks, Pako, but I'm afraid that doesn't work. I have my zones like this:

Code: Select all

eg.globals.Rom[1] = 'WC'
eg.globals.Rom[2] = 'Garderoberom'
eg.globals.Rom[3] = 'Midtsoverom'
eg.globals.Rom[4] = 'Hj├©rnesoverom'
eg.globals.Rom[5] = 'Hovedsoverom'
eg.globals.Rom[6] = 'Bad'
eg.globals.Rom[7] = 'Stue'
eg.globals.Rom[8] = 'Kj├©kken'
eg.globals.Rom[9] = 'Kino'
eg.globals.Rom[10] = 'Biljardrom'
eg.globals.Rom[11] = 'Kjellerkontor'
eg.globals.Rom[12] = 'Treningsrom'
eg.globals.Rom[13] = 'Gjesterom'
And if I try this:

Code: Select all

print eg.globals.Rom[8].decode(eg.systemEncoding)
I get this:

Code: Select all

14:16:39      Kjøkken
So what I need is a way to get this to show "kj├©kken" instead. I use it amongst other things in this print statement:

Code: Select all

print '%s.: Temperatur: %s, termostattemperatur: %s, tidspunkt: %s\n'%((eg.globals.Rom[int(Rom)]),eg.globals.Romtemperatur[Rom],eg.globals.Termostatemperatur[Rom], eg.globals.Tid[Rom])
Here the eg.globals.Rom[int(Rom)] is the variable that contains ├©. Is there a way to get that right?
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: How do I print unicode in variables?

Post by Pako »

Mastiff wrote:Is there a way to get that right?
Of course.
I wrote, correctly it should be as follows:

Code: Select all

testvariable = u'├©├ª├Ñ'
So your real variables should look like this:

Code: Select all

eg.globals.Rom[1] = u'WC'
eg.globals.Rom[2] = u'Garderoberom'
eg.globals.Rom[3] = u'Midtsoverom'
eg.globals.Rom[4] = u'Hj├©rnesoverom'
eg.globals.Rom[5] = u'Hovedsoverom'
eg.globals.Rom[6] = u'Bad'
eg.globals.Rom[7] = u'Stue'
eg.globals.Rom[8] = u'Kj├©kken'
eg.globals.Rom[9] = u'Kino'
eg.globals.Rom[10] = u'Biljardrom'
eg.globals.Rom[11] = u'Kjellerkontor'
eg.globals.Rom[12] = u'Treningsrom'
eg.globals.Rom[13] = u'Gjesterom'
Pako
You know flattr ? You can Image
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: How do I print unicode in variables?

Post by Mastiff »

Aha, now I understand! I thought the u would be part of the variable! Silly me. Thanks a lot! That even fixed the problem I had with the webserver not eating these letters. :mrgreen:
Post Reply