我在這個項目中使用了兩個文件。 Snapchat.py和test.py在python中打印json結果
Snapchat.py包含以下(表明重要的部分):
def add_friend(self, username):
"""Add user as friend
Returns JSON response.
Expected messages:
Success: '{username} is now your friend!'
Pending: '{username} is private. Friend request sent.'
Failure: 'Sorry! Couldn't find {username}'
:param username: Username to add as a friend
"""
r = self._request('friend', {
'action': 'add',
'friend': username,
'username': self.username
})
return r.json()
文件test.py,我目前的工作有以下代碼:
這裏#including Snapchat in test.py
from snapchat import Snapchat
s = Snapchat()
username = raw_input('Enter your username: ')
password = raw_input('Enter your password: ')
friend = raw_input('Enter friend name: ')
s.login(username, password)
s.add_friend(friend)
最重要的部分是:
Returns JSON response.
Expected messages:
Success: '{username} is now your friend!'
Pending: '{username} is private. Friend request sent.'
Failure: 'Sorry! Couldn't find {username}'
我想要在命令行界面的test.py文件末尾打印該響應。
雖然我不知道如何做到這一點,但我已經嘗試將它導入到test.py文件並打印出來,但不能正常工作。
我在這裏沒有看到任何對R語言的引用,所以我刪除了[r]標記 –