0

I use Pycharm/Intellij Idea. When I print some data with diacritics into console, it prints in proper format.

print u"čipsy"
čipsy

But when I print the list of items containing diacritics, it prints them in raw format.

print [u"čipsy"]
[u'\u010dipsy']

Is it possible to make my IDE to print it in a proper format? So the input would be:

print [u"čipsy"]
['čipsy']
Milano
  • 18,048
  • 37
  • 153
  • 353

1 Answers1

0

The reason this happens is that when you print the string, it internally prints str(s). When you print the list, the str() method of the list internally fetches the repr() of the list items and prints that.

E.g.

>>> s = u'\u010dipsy'
>>> print s
čipsy
>>> print repr(s)
u'\u010dipsy'

For more info on the differences between str and repr, see this question: Difference between __str__ and __repr__ in Python

So as far as I'm aware, the answer to your original question "Is it possible to make my IDE to print it in a proper format?!" is probably no, unless you subclassed list and overrode the str method to have the behaviour you want. You'd then need to make sure the list you're wanting to print is an instance of your special list subclass.

Community
  • 1
  • 1
Tom Dalton
  • 6,122
  • 24
  • 35