Problem with __str__ method and character encoding
gialloporpora
gialloporpora at gmail.com
Fri Dec 7 09:14:07 EST 2012
Dear all,
I have a problem with character encoding.
I have created my class and I have redefined the __str__ method for
pretty printing. I have saved my file as test.py,
I give these lines:
>>> from test import *
>>> a = msgmarker("why", u"perché", 0)
>>> print a
UnicodeError
>>> print a.__str__()
OK
Why? Really, I don't understand what is wrong.
I am using Python 2.7
This is the code in my test.py:
class msgmarker(object):
def __init__(self, msgid, msgstr, index, encoding="utf-8"):
self._encoding =encoding
self.set(msgid, msgstr)
self._index = index
def __repr__(self):
return "<msgmarker object>"
def __str__(self):
return u'msgid: "%s"\nmsgstr: "%s"' %(self.msgid, self.msgstr)
--
*Antivirus aggiornato: e siamo sicuri che basti? * - http://bit.ly/SXuDAc
Sto ascoltando: *Robert Plant – One More Cup of Coffee (Valley Below) *
- http://bit.ly/TtyHMq
More information about the Python-list
mailing list