Some of the examples I've seen:
k_name = u"value"
k_name = "value"
- Code: Select all
prop[u"name"] = value
prop["name"] = value
self.debugLog(u"Log message")
self.debugLog("Log message")
list = [u"one", u"two", u"three"]
list = ["one", "two", "three"]
To me, things that should not change, such as property keys references for checkboxes and hidden things from Devices.xml, don't need the u"" treatment. Values being entered into text fields with the UI do, unless the values are limited to only specific ones like in a validation list (which I don't think need the treatment either).
And if an entered value can contain unicode characters, how do I assure it's stored into and retrieved/logged from the pluginProps or other areas as such?
How important is it that log messages and other literals use the u"" format?
To actually test some of this. I created a device with unicode characters in its name and boy did I see errors in the Indigo log from my plugin! Any place logging is done for the entire Device object (such as in the following code) it fails, even if I try and unicode() it:
- Code: Select all
print (u"device: %s" % (unicode(dev)))
So I experimented and get:
- Code: Select all
>>> dev=indigo.devices[1190300210]
>>> print dev
Traceback (most recent call last):
File "<console>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 9: ordinal not in range(128)
>>> print unicode(dev)
Traceback (most recent call last):
File "<console>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 9: ordinal not in range(128)
>>> print dev.name
Traceback (most recent call last):
File "<console>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 9: ordinal not in range(128)
>>> print unicode(dev.name)
Traceback (most recent call last):
File "<console>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 9: ordinal not in range(128)
- Code: Select all
>>> print dev.name.encode("utf-8")
So how do I wrap my debugging statements with references to the entire Device object to make them work? Or are device names supposed to be ASCII only (seems unlikely) so this never shows up in real-world cases?
I hope that the behavior isn't just a version 5 artifact that I'm seeing. I'd hate to waste too many of your brain cycles if that's the case.
Any advise would be appreciated.