I am writing a Django application, and I often use the Python backtick operator to convert integers to strings.
Recently, I found that a form in my application was broken. After rewriting several backticks into str(), the application was fixed.
Specifically, where course is an object, I changed
“course.id \
into str(course.id) to fix the application.
When does the backtick operator work, and when does it not?
Backticks are an alias for
repr(), not forstr(). There are types whererepr()andstr()return the same value, hence the confusion.For user output, you should always use
str(). Backticks probably shouldn’t be used at all — they have been removed in Python 3.x since they were considered a misfeature.