Class 这个Python类有什么错?属性错误:';非类型';对象没有属性';用户名';

Class 这个Python类有什么错?属性错误:';非类型';对象没有属性';用户名';,class,python-2.7,object,Class,Python 2.7,Object,嘿,我正在尝试使我的第一个类我的代码如下: class Twitt: def __init__(self): self.usernames = [] self.names = [] self.tweet = [] self.imageurl = [] def twitter_lookup(self, coordinents, radius): twitter = Twitter(auth=auth) coordinents = coordinen

嘿,我正在尝试使我的第一个类我的代码如下:

class Twitt:
def __init__(self):
    self.usernames = []
    self.names = []
    self.tweet = []
    self.imageurl = []

def twitter_lookup(self, coordinents, radius):
    twitter = Twitter(auth=auth)
    coordinents = coordinents + "," + radius
    print coordinents
    query = twitter.search.tweets(q="", geocode='33.520661,-86.80249,50mi', rpp=10)
    print query
    for result in query["statuses"]:
        self.usernames.append(result["user"]["screen_name"])
        self.names.append(result['user']["name"])
        self.tweet.append(h.unescape(result["text"]))
        self.imageurl.append(result['user']["profile_image_url_https"])
我想做的是像这样使用我的类:

test = Twitt()
hello = test.twitter_lookup("38.5815720,-121.4944000","1m")
print hello.usernames
这不起作用,我不断得到:“AttributeError:'NoneType'对象没有属性'UserName'”


也许我只是误解了教程,或者是试图用错了。感谢您的帮助。

您的功能
twitter\u lookup
正在修改
Twitt
对象。您没有让它返回任何类型的值,因此当您调用
hello=test.twitter\u lookup()
时,没有可分配给
hello
的返回值,它的结果是
None
。请尝试
test.usernames

或者,让
twitter\u lookup
函数将其结果放入某个新对象(可能是字典?)并
return
it。这可能是更明智的解决方案


此外,该函数接受一个
coordinents
(它的“坐标”)参数,但随后将其丢弃并使用硬编码值代替。

我看到错误是
test。twitter_lookup(“38.5815720,-121.4944000”,“1m”)
不返回任何内容。如果你想要用户名,你需要这样做

test = Twitt()
test.twitter_lookup("38.5815720,-121.4944000","1m")
test.usernames

啊,非常感谢,我现在明白了。是的,我在准备“coordinents”(我拼写不好时哈哈)参数,但格式有问题,所以我硬编码了一组坐标,我知道这会有用的。谢谢!我现在明白了。@ZachJohnson欢迎您,如果可以的话,选择正确的答案:)那太好了。