Ah, thats much neater than %, which isn't very pythonic...The only thing is that if you plan on sharing your code, others must have python 2.6 or above.
Doubt it. 3.x isn't meant to be backwards compatibile with 2.x. Also, isn't % also a modulus operator in normal circumstances. Maybe thats what it has become in 3.x?
Could you not just use the str() statement? Example:
ticketCost = 10
print "The cost of your ticket is $" + str(ticketCost) + "."
Or is that the same thing?
+1
String formatting is the way to go, a lot more flexibility than using str - since you get all the featurs of the formatting mini-language too.
Using string formatting (using the {0} type format) has the added benefit of being able to be overwritten for custom classes (you simply define a __format__ method for your class): so you can define what a format string of "+02.8d" actually means for your class, or you could even define your own format mini-langauge for your class.
Tony - Happy to try to help.
Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups
Bookmarks