6

I have recently come to understand that we can use the following as a shorthand for repr(x) in Python:

`x`

However, I have rarely seen this in practice. Is it considered to be bad practice or unpythonic? Or are there any other reasons for which it is rarely used?

arshajii
  • 127,459
  • 24
  • 238
  • 287
  • 6
    It was removed from Py3k. For me is enough reason not to use it. – JBernardo Oct 11 '12 at 00:59
  • And they were deprecated because they are hard to read and verging on implicit when `repr` is so much more clear. See also http://stackoverflow.com/questions/1673071/what-do-backticks-mean-to-the-python-interpreter-num – msw Oct 11 '12 at 01:00
  • It was totally worth it to save 4 characters when we were paying > $1/GB for harddrive space, now harddrives got cheaper. Noone cares much if you waste 0.0000004 cents – John La Rooy Oct 11 '12 at 01:09

1 Answers1

7

I don't think many people would argue that it's Pythonic especially since it's been removed from Python3

Prior to that, I would never use it in real code. The problem being that quite a few developers didn't know what it was for, and it's not very easy to search for.

There has also been a move in Python3 to have .__next__() method instead of .next() for iterators, which strengthens the idea that repr(x) calls x.__repr__() etc.

John La Rooy
  • 295,403
  • 53
  • 369
  • 502