【发布时间】:2022-12-18 12:21:10
【问题描述】:
if thisuser["handle"] == "Talon":
tweet_text = thisuser["handle"] + ", the Eternal Leader of Civitas Nihilium, has just logged into the trans-dimensional portal, and is available to converse!"
else:
tweet_text = thisuser["handle"] + " has just logged into the trans-dimensional portal, and is available to converse!"
我对 Python 和一般编程还很陌生,所以我不确定为什么这对我不起作用。这是基于 Python 2.7 的 Mystic Python。如您所见...
在添加此 IF 语句之前,代码运行良好。
thisuser["handle"] 有时会在其中包含字符串 "Talon"。如果是这样,我想在推文中包含 tweet_text 字符串。那没有发生,所以我在这里做错了什么?
我知道这可能是一个简单的答案,这让它变得更加令人沮丧。先感谢您。
詹姆士 :)
这是完整的代码...
import tweepy
import sys
from mystic_bbs import *
consumer_key = 'yVRqcf4IDbs4IjrQGqiE0gT3n'
consumer_secret = 'ALLwUd0nuXvHA8jrMKfu5CRdy0BwOa72EXaklbdWyB6wYf57X7'
access_token = '1599041954221785089-iMfpEhEEZqaAwc0Bi0SAcshF6oUVw7'
access_token_secret = 'NJhcJGkpH1dhfX9UX5qcSwFxHu4gHv9f62PdoKDnJgLPY'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
thisuser = getuser(0); # read the currently logged in user into thisuser
writeln("|11 STANDBY Updating Status within Profundum!");
api = tweepy.API(auth)
if thisuser["handle"] == "Talon":
tweet_text = thisuser["handle"] + ", the Eternal Leader of Civitas Nihilium, has just logged into the trans-dimensional portal, and is available to converse!"
else:
tweet_text = thisuser["handle"] + " has just logged into the trans-dimensional portal, and is available to converse!"
api.update_status(status=tweet_text)
所以 thisuser["handle"] 是登录我的 BBS 的人的用户名。在这种情况下,用户名是 Talon。发送的推文看起来像这样......
TALON 刚刚登录到跨维度门户,可以交谈了!”
【问题讨论】:
-
你的问题很不清楚,而且断章取意。请提供清楚的minimal reproducible example
-
“里面有字符串“Talon””-这与字符串不同是“利爪”-
"Talon" in thisuser["handle"] -
啊好的谢谢我真的不明白这一切是如何运作的。我猜 -1 是坏事吧?
-
所以我试图查看 handle 是否与名称“Talon”匹配,如果匹配,则语句为真,如果匹配,则我们转到 else。上帝,我希望这是有道理的。 :/
-
这是有道理的,但如果没有minimal reproducible example,我们将无能为力,因为您的代码看起来不错
标签: python python-2.7 tweepy