Python decode/encode

101 views
Skip to first unread message

Rémi Deletrain

unread,
Nov 26, 2015, 8:49:41 AM11/26/15
to Python Programming for Autodesk Maya
Hi everybody,

I try to encode a string utf-8

myString = "" === Pr \ u00e9sentation of ... === ""
with "\ u00e9", which is the letter "é"

but I happens by no means has transform my string properly.

I decode with "cp1252"
and again with "latin1"

with variable myString I have no problem, but on a much longer text I have another problem. I think there are different encoding type in the text that I have ...
In the end I just want a "utf-8" format.

I tried with unidecode module, but suddenly I lost all the accents that are important in this text.

someone a solution?

Mark Jackson

unread,
Nov 26, 2015, 11:50:58 AM11/26/15
to python_inside_maya
I'd take a look at the codecs module in Python, certainly if you're looking to read/write the data from file. We're doing a lot of localisation for language support at the moment

            with codecs.open(textfilepath, 'w', encoding='utf8') as fp:
                fp.write(text_to_write)
                fp.close()

cheers

Mark

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/069d653a-ca78-465c-abc8-a1093eac17bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-------------------------------------
Mark Jackson
CEO / Technical Director
red9consultancy.com

Rémi Deletrain

unread,
Nov 26, 2015, 2:30:56 PM11/26/15
to Python Programming for Autodesk Maya
Hi Mark,

My file is xml. I use ElementTree for get data.

And for get text data I just have myText = myElement.text

I don't know other wy for xml file...

Mark Jackson

unread,
Nov 29, 2015, 4:21:19 PM11/29/15
to python_inside_maya
In that case can you not just use the internal encoding?

ET.ElementTree(testtag).write('testunicode.xml',encoding="UTF-8",xml_declaration=True)

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Rémi Deletrain

unread,
Dec 1, 2015, 3:02:47 AM12/1/15
to Python Programming for Autodesk Maya
I tried this way but it does not work properly...
I have always problem with encode format

Marcus Ottosson

unread,
Dec 1, 2015, 3:21:30 AM12/1/15
to python_in...@googlegroups.com
It doesn't sound like libraries will solve your problem, but rather gaining a deeper understanding of encoding and strings. There are some very good PyCon conferences that I think should touch on what you are looking to understand.


On 1 December 2015 at 08:02, Rémi Deletrain <remi.de...@gmail.com> wrote:
I tried this way but it does not work properly...
I have always problem with encode format

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Rémi Deletrain

unread,
Dec 1, 2015, 3:29:12 AM12/1/15
to Python Programming for Autodesk Maya
thank you marcus I'll watch it whenever I can! 
Reply all
Reply to author
Forward
0 new messages