0
這是中的代碼的副本挖掘社交網絡的書。python和redis,語法不清
我是這方面的新人,也是redis。我想了解$
在這方面的含義。還打印%s
,這是什麼意思?
這是(從:https://github.com/ptwobrussell/Mining-the-Social-Web):下面的源代碼
import sys
import redis
from twitter__util import getRedisIdByScreenName
# A pretty-print function for numbers
from twitter__util import pp
r = redis.Redis()
screen_names=['user1','user2']
def friendsFollowersInCommon(screen_names):
r.sinterstore('temp$friends_in_common',
[getRedisIdByScreenName(screen_name, 'friend_ids')
for screen_name in screen_names]
)
r.sinterstore('temp$followers_in_common',
[getRedisIdByScreenName(screen_name, 'follower_ids')
for screen_name in screen_names]
)
print 'Friends in common for %s: %s' % (', '.join(screen_names),
pp(r.scard('temp$friends_in_common')))
print 'Followers in common for %s: %s' % (', '.join(screen_names),
pp(r.scard('temp$followers_in_common')))
# Clean up scratch workspace
r.delete('temp$friends_in_common')
r.delete('temp$followers_in_common')
if __name__ == "__main__":
if len(screen_names) < 2:
print >> sys.stderr, "Please supply at least two screen names."
sys.exit(1)
friendsFollowersInCommon(screen_names[1:])
這部分怎麼樣? r.sinterstore('temp $ followers_in_common', [getRedisIdByScreenName(screen_name,'follower_ids') for screen_name in screen_names] – user1511208 2012-07-23 10:03:39
那麼,它呢? – 2012-07-23 10:05:48
我的意思是,[]第一部分是方法然後for循環。這是什麼意思? – user1511208 2012-07-23 10:11:23