class Direction:
def __init__(self,position=0):
self.position=position
self.dir=1
def display(self):
print("Positon:",self.position,",Direction: Up")
现在正在打印什么:
>>> a=Direction(3)
>>> a.display()
Positon: 3 ,Direction: Up
我想删除3之后的空格。
答案 0 :(得分:2)
使用a = catch_error(nokodoc) do |doc|
doc.search('#element-1').attribute('href').text
end
def catch_error(doc)
yield doc
rescue => ex
puts doc.title # Or something else that identifies the document
puts ex.message
puts ex.backtrace.join("\n")
end
。您的rescue
函数如下所示:
format
答案 1 :(得分:0)
像这样:
>>> print("Position: ", self.position, ", Direction: Up", sep='')
Position: 3, Direction: Up
或者:
>>> print("Position: %s, Direction: Up" % self.position)
Position: 3, Direction: Up