Problem with __str__ method and character encoding

gialloporpora gialloporpora at
Fri Dec 7 15:14:07 CET 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,
I give these lines:

 >>> from test import *
 >>> a = msgmarker("why", u"perché", 0)
 >>> print a
 >>> print a.__str__()
Why? Really, I don't understand what is wrong.
I am using Python 2.7
This is the code in my

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? * -
Sto ascoltando: *Robert Plant – One More Cup of Coffee (Valley Below) * 

More information about the Python-list mailing list