【发布时间】:2013-12-07 01:01:37
【问题描述】:
我无法获得我想要的代码输出。我想测试一个类和类中定义的函数。这是我的代码:
class Book:
# the class constructor
def __init__(self, author, title, book_id):
self.title = title
self.author = author
self.book_id = book_id
def __str__(self):
s = "Books("+self.author+", "+self.title+", "+self.book_id+")"
return s
def __repr__(self):
return str(self)
我试图测试它是这样的:
>>> author="Dr. Suess"
>>> title="The Cat in the Hat"
>>> book_id="12345"
>>> Book
<class '__main__.Book'>
>>>
我得到的输出是最后一行。我可能做错了,但我不知道如何测试它。如果有人能告诉我,那就太好了!
【问题讨论】:
-
你想要的输出是什么?
标签: python function class testing python-3.3