Я пытаюсь получить доступ к классу из другого класса, но я столкнулся с этой проблемой.AttributeError: объект 'str' не имеет атрибута <CLASS NAME>
Это класс, к которому я пытаюсь получить доступ.
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
И это уменьшенная версия класса, в котором я ошибаюсь.
import sqlite3
import random
from app.models.monDAO import monDAO
from app.models.charDAO import CharDAO
from app.models.dunDAO import DunDAO
from app.controllers.twt_print import TwtPrinter
class GameManager:
def testDB(self):
print("hello world")
conn = sqlite3.connect('DunSuciRun.sqlite')
c = conn.cursor()
this = """SELECT * FROM CHARACTERS"""
c.execute(this)
getStuff = c.fetchall()
charTuple = getStuff[0]
cha = CharDAO(charTuple[0], charTuple[1],charTuple[2],charTuple[3],charTuple[4])
print(cha.name.split(' ')[0])
def test(self):
self.twt_print = TwtPrinter
testing = "testing"
print testing
# self.twt_print = TwtPrinter
self.twt_print.printTweet("1""2")
Ошибка в вопросе заключается в следующем:
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
Возможный дубликат объекта [AttributeError: 'module не имеет атрибута] (http://stackoverflow.com/questions/1250103/attributeerror-module-object-has-no-attribute) – tinySandy