0

这是挖掘社交网络书的代码副本。

我是这个领域的新手,也是 Redis 的新手。$我想了解在这种情况下是什么意思。还有print with %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:])
4

1 回答 1

1

$符号只是键名的一部分。它分隔名称部分。我通常:用于相同的目的(例如users:123

%s部分是字符串格式

于 2012-07-23T09:35:42.283 回答