Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python accent graves bad practice?

Tags:

python

repr

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?

like image 816
arshajii Avatar asked Oct 11 '12 00:10

arshajii


1 Answers

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.

like image 116
John La Rooy Avatar answered Nov 13 '22 15:11

John La Rooy