Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Problem with __str__ method and character encoding

Reply
Thread Tools

Re: Problem with __str__ method and character encoding

 
 
peter
Guest
Posts: n/a
 
      12-07-2012
On 12/07/2012 11:17 AM, gialloporpora wrote:
> Risposta al messaggio di gialloporpora :
>
>> This is the code in my test.py:

>
> Sorry, I have wrongly pasted the code:
>
>
> 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)
>
> def isUntranslated(self):
> return self.msgid==self.msgstr
>
> def isFuzzy(self):
> return self.msgstr[0:2]=="=="
>
> def markFuzzy(self):
> self.msgstr = "==%s" %(self.msgstr)
> def set(self, msgid, msgstr):
> if not(isinstance(msgid, unicode)): msgid =
> msgid.decode(self._encoding)
> if not(isinstance(msgstr, unicode)): msgstr =
> msgstr.decode(self._encoding)
> self.msgid = msgid
> self.msgstr = msgstr
>
> def setmsgstr(self, msgstr):
> if not(isinstance(msgstr, unicode)): msgstr =
> msgstr.decode(self._encoding)
> self.msgstr = msgstr
>
> def getIndex(self):
> return self._index
> def getIndex(self):
> return self._index
>
>
>
>
>
>
>

what do you meant whe you say 'pretty print' ??.

is you just want to print a object in a nice format, you can use pprint

from pprint import pprint

nasty_dict = { 'hellou': bybye,
.....

Imagine that nasty_dict have many complex object. For pretty print in
the python console you can do this:

pprint(nasty_dict).

Is you use ipython:

%page nasty_dict
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Problem with __str__ method and character encoding Chris Angelico Python 0 12-07-2012 02:33 PM
substitution __str__ method of an instance netimen Python 5 10-23-2008 09:49 PM
cpython list __str__ method for floats [david] Python 6 09-12-2007 11:48 PM
Re: "Aliasing" an object's __str__ to a different method Jeffrey E. Forcier Python 2 07-24-2005 02:25 PM
"Aliasing" an object's __str__ to a different method Jeffrey E. Forcier Python 7 07-24-2005 12:45 AM



Advertisments