LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python has ticks, backticks and forward ticks (https://www.linuxquestions.org/questions/programming-9/python-has-ticks-backticks-and-forward-ticks-927980/)

S. Chapelin 02-06-2012 07:59 PM

Python has ticks, backticks and forward ticks
 
I am reading Thinking in Python, by Bruce Eckel, which I find fascinating.
However, I came across the folowing line:
Code:

      return ´self´ + self.val
which got the following interpreter complaint:
Code:

  File "SingletonPattern.py", line 11
    return ´self´ + self.val
          ^
SyntaxError: invalid syntax

Ok, so I removed the ticks:
Code:

Traceback (most recent call last):
  File "SingletonPattern.py", line 22, in <module>
    print x
  File "SingletonPattern.py", line 11, in __str__
    return self + self.val
TypeError: unsupported operand type(s) for +: 'instance' and 'str'

Then I used ordinary single quotes, which produced a string combining self with self.val. Not good.
Finally I dug up the solution in the code folder that comes with the html book and found the following:
Code:

      return `self` + self.val
I didn't know python had backticks, like bash.
When I google ticks in python, the search comes up with timer ticks.
Can someone explain ticks to me or point me to a good doc?

ntubski 02-06-2012 09:16 PM

Quote:

Can someone explain ticks to me or point me to a good doc?
The definitive doc is at http://www.python.org/doc/.

I find back ticks only in the grammar for 2.x, not 3.x:

5.2.9. String conversions

audriusk 02-08-2012 01:45 PM

Backticks are equivalent to repr() function. They should be avoided, as they're less readable and no longer available in Python 3.

bigearsbilly 02-10-2012 04:22 AM

quite a few scripting languages have backticks, ruby and perl for example.


All times are GMT -5. The time now is 12:20 AM.