Hello,
I'm struggling to get (or even set) the encoding used when a byte
string is printed in the maya Script Editor.
I have discovered that sys.stdout has been assigned to maya.Output.
This class doesn't have an encoding attribute.
>From the tests I've done, I have found that maya 2011 is using cp1252
(which is my locale encoding) et maya 2009, ascii. Unfortunately, all
the tests I've done to find the encoding used returns the same
information in 2009 or 2011.
Here is a code sample to show my research:
{{{
import sys
try:
print "Stdout Encoding:", sys.stdout.encoding
except AttributeError:
print "No stdout encoding"
print "Default Encoding:", sys.getdefaultencoding()
print "Filesystem Encoding:", sys.getfilesystemencoding()
import locale
print "Locale:"
print locale.getpreferredencoding()
print locale.getlocale()
print locale.getdefaultlocale()
print "Non-ascii char conversion:"
uni = u"\xe9" # "é" character
DEFAULT_ENCODING = "cp1252"
try:
encoding = sys.stdout.encoding or DEFAULT_ENCODING
except AttributeError:
encoding = DEFAULT_ENCODING
print "encoding:", encoding
bstr = unicode(uni).encode(encoding, "replace")
print "repr:", repr(bstr)
print "unicode:", uni
try:
print "byte string:", bstr
except UnicodeDecodeError, err:
print err
}}}
In Maya 2009 I have:
{{{
Stdout Encoding: No stdout encoding
Default Encoding: ascii
Filesystem Encoding: mbcs
Locale:
cp1252
('fr_FR', 'cp1252')
('fr_FR', 'cp1252')
Non-ascii char conversion:
encoding: cp1252
repr: '\xe9'
unicode: é
byte string: 'ascii' codec can't decode byte 0xe9 in position 0:
ordinal not in range(128)
}}}
In Maya2011:
{{{
Stdout Encoding: No stdout encoding
Default Encoding: ascii
Filesystem Encoding: mbcs
Locale:
cp1252
('fr_FR', 'cp1252')
('fr_FR', 'cp1252')
Non-ascii char conversion:
encoding: cp1252
repr: '\xe9'
unicode: é
byte string: é
}}}
As you can see last line of the two outputs, Maya 2011 looks to use
cp1252 for encoding whereas Maya 2009 use ascii.
- Why Maya 2009 and Maya 2011 behave differently?
- How can I get the encoding used when printing? I.e. maya.Output
encoding?
- Is it possible to set the encoding? (I'd rather use utf8)
(I'm using maya2009 x64 SP1 and maya2011 x64 hotfix3)
Many thanks!
--
http://groups.google.com/group/python_inside_maya