快考toefl了,又产生了考前综合症,只能看看 programming collective intellifence放松放松。。哎革命尚未成功,同志还需努力,什么时候不用再去考试。。
闲话不说了,在programming collective intelligence 这本书中,有大量的python的实例。不得已,得了python的开发平台。工欲善其事,必先利其器。
最好的选择:eclipse+pydev,python选择2.7,不要选择3.x,语法规则不同
1. click help->install eclipse new plug->name PyDev: site:http://pydev.sourceforge.net/updates/, restart eclipse
2. set python in eclipse: eclipse->window->preference->PyDev->Interpreter->python, choose python.exe
3. create a pydev project with python 2.7.
4. set project properties, pydev->pythonPath, add below folders
然后建立python工程:
然后建立两个model:
一个放定义好的函数,一个放测试代码
调试的时候也很方便,也可以用print打到控制台上
用tortoisessvn下载 书中提供的基本库:http://pydelicious.googlecode.com/svn/trunk
打开cmd,打开下载目录,安装setup.py:
在eclipse中配置,更新模块,点apply:
现在敲delicious.py:
from pydelicious import get_popular,get_userposts,get_urlposts
def initializeUserDict(tag,count=5):
user_dict={}
# get the top count' popular posts
for p1 in get_popular(tag=tag)[0:count]:
# find all users who posted this
for p2 in get_urlposts(p1['url']):
user=p2['user']
user_dict[user]={}
return user_dict
再敲test.py:
from delicious import *
delusters=initializeUserDict('programming')
for i in delusters:
print i
运行test.py,出错:400 not found
解决方案:
Changing like 457 in __init__.py to: rss = http_request('http://feeds.delicious.com/v2/rss').read()
运行,成功:
返回最popular的URL的提交用户字典,当前所有值都是空的。只有键值。
现在可以动手实践了。