我的代码可以在这里找到:https ://github.com/thekarangoel/HackerNewsAPI/blob/master/hn.py
测试用例是这样的:
from hn import HN
hn = HN()
for story in hn.get_top_stories()[:10]:
print story.print_story()
print '*' * 50
print ''
这会像这样打印我的输出:
.....
.....
.....
**************************************************
Rank: 3
Story ID: 6231993
Title: Pipe Dream? 3D-Printed Model of Hyperloop Created
Link: http://news.yahoo.com/pipe-dream-3d-printed-model-hyperloop-created-192033757.html
Domain: yahoo.com
Points: 1
Submitted by: evo_9
Number of comments: 0
Link to comments: http://news.ycombinator.com/item?id=6231993
None
**************************************************
Rank: 4
Story ID: 6231992
Title: What colour are your bits?
Link: http://ansuz.sooke.bc.ca/entry/23
Domain: bc.ca
Points: 1
Submitted by: grey-area
Number of comments: 0
Link to comments: http://news.ycombinator.com/item?id=6231992
None
.....
.....
注意None
每张印刷品末尾的 ?为什么会在那里?代码有什么问题?