Today’s reason why I love Ruby: I had a text file and I wanted to take each line and use its content as a string to construct list items as HTML output. Here’s what I wrote:
File.open(“/Users/gabe/file.txt”).each { |line| puts “\t<li>” + line.slice(0..-2) + “</li>” #using slice to knock off the \n from the end of the line }
Ruby should take a hint from Staples and adopt a new motto: “That was easy.”
and in python: list = [ ("\t%s" % line.strip()) for line in open("/Users/gabe/file.txt").readlines() ]