我试图从另一个类访问一个类,但遇到了这个问题。在
这就是我要访问的类。在
import tweepy
ckey= '**********************'
csecret= '**********************'
atoken= '**********************'
asecret= '**********************'
class TwtPrinter:
def printTweet(self, user, text):
auth = tweepy.OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
api = tweepy.API(auth)
for status in tweepy.Cursor(api.user_timeline).items():
try:
api.destroy_status(status.id)
except:
pass
这是一个缩小版的类,我在这里遇到了错误。在
^{pr2}$问题在于:
C:\Python27\python.exe C:/Users/Jensi/PycharmProjects/DSR.02/app/controllers/game_manager.py
Traceback (most recent call last):
File "C:/Users/Jensi/PycharmProjects/DSR.02/app/controllers/game_manager.py", line 14, in <module>
class GameManager:
File "C:/Users/Jensi/PycharmProjects/DSR.02/app/controllers/game_manager.py", line 241, in GameManager
test("")
File "C:/Users/Jensi/PycharmProjects/DSR.02/app/controllers/game_manager.py", line 32, in test
self.twt_print = TwtPrinter
AttributeError: 'str' object has no attribute 'twt_print'
Process finished with exit code 1
在
game_manager.py
,第241行(问题中未显示)中,代码正在调用test("")
,但是test()
不接受任何显式参数。它是一个实例方法。你应该这样称呼它:例如,作为一个没有参数的
GameManager
实例的方法。在line 241, in GameManager test("")
您正在将一个空字符串作为
test
函数传递给self
。您应该传递一个类实例。实际上,您不应该传递任何东西,因为如果您的调用约定和类定义是正确的,python将为您完成这项任务。在相关问题 更多 >
编程相关推荐