LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-06-2012, 07:59 PM   #1
S. Chapelin
Member
 
Registered: Jan 2010
Location: Quebec
Posts: 72

Rep: Reputation: 5
Question 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?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-06-2012, 09:16 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 1,423

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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
 
Old 02-08-2012, 01:45 PM   #3
audriusk
Member
 
Registered: Mar 2011
Location: Klaipėda, Lithuania
Distribution: Slackware
Posts: 131

Rep: Reputation: 60
Backticks are equivalent to repr() function. They should be avoided, as they're less readable and no longer available in Python 3.
 
2 members found this post helpful.
Old 02-10-2012, 04:22 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,048

Rep: Reputation: 95
quite a few scripting languages have backticks, ruby and perl for example.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enabling dynamic ticks pcondosta Linux - Hardware 0 07-22-2007 06:45 PM
Get cpu ticks c function entz Programming 8 04-17-2007 11:22 AM
ticks pacco Linux - General 1 02-14-2006 12:31 PM
All those free SPU ticks marghorp Linux - General 2 11-09-2004 06:05 AM
Finer Clock Ticks gothrog Linux - Networking 2 06-25-2004 04:24 PM


All times are GMT -5. The time now is 02:55 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration