Re: Problem with __str__ method and character encoding

Discussion in 'Python' started by peter, Dec 7, 2012.

  1. peter

    peter Guest

    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
    peter, Dec 7, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeffrey E. Forcier
    Replies:
    7
    Views:
    313
    Christopher Subich
    Jul 24, 2005
  2. Jeffrey E. Forcier
    Replies:
    2
    Views:
    310
    Jeffrey E. Forcier
    Jul 24, 2005
  3. [david]
    Replies:
    6
    Views:
    296
    John Machin
    Sep 13, 2007
  4. netimen
    Replies:
    5
    Views:
    257
    Steven D'Aprano
    Oct 23, 2008
  5. Chris Angelico
    Replies:
    0
    Views:
    152
    Chris Angelico
    Dec 7, 2012
Loading...

Share This Page