2017-05-23 1 views
0

Tweepyのapi.update_status関数に複数の変数を渡そうとしています。 Cursorから2つの変数を呼び出そうとしていますが、1つの変数のみを出力します。Tweepyに複数の変数を渡すapi.update_status

for (id, tweet_id, screen_name, created_at, text) in cursor: 
url='https://www.threatminer.org/host.php' 
payload={'q': text, 'api': 'True', 'rt': '6'} 
headers={ 
    'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'} 
r=requests.get(url, params=payload, headers=headers) 
json_data=r.json() 
status_message=json_data['status_message'] 
status = text and "Was found in a Tweet" 
if "Results found." in status_message: 
    api=tweepy.API(auth) 
    api.update_status(text, screen_name) 
    print(text, screen_name) 
    print(r.url) 
    print json_data 
else: 
    print('Nothing') 
+0

「複数の変数をapi.update_statusに渡す」とはどういう意味ですか?送信するテキストを含む2つ以上の変数がありますか? –

+0

@RodrigoLeiteそれは正しいです。私は、送信したいテキストを含む複数の変数を持っています。 –

+0

私は回答 –

答えて

1

あなたのコメントで述べたように、送信するテキストを含む複数の変数があります。この問題を解決するには、それらを連結して単一の文字列を形成する必要があります。

あなたがそうのように、フォーマットされた文字列を使用するオプション持つ3.6以降のPythonを使用している場合:この場合

string1 = "My name is" 
string2 = "dog!" 
string3 = f"{string1} {string2}" 

を、string3My name is dog!に等しくなります。

string1 = "My name is" 
string2 = "dog!" 
string3 = "{} {}".format(string1, string2) 

別のオプションは、+演算子を使用することですが、それはパフォーマンス上の理由から、眉をひそめています:あなたは、Pythonにはいないのであればただし、3.6以降、あなたはそうのように、これを行うにはformat()機能を使用する必要があります。

+0

を提出しました。 –

関連する問題