pyFaceGraph icon indicating copy to clipboard operation
pyFaceGraph copied to clipboard

Accessing only existing data attributes on Node instances

Open anentropic opened this issue 14 years ago • 0 comments

Node class docstring says: "...accessing non-existent attributes will still return a Graph... You’ll have to check for the presence of a key first, to make sure what you're trying to access actually exists"

    def user_location(user_id):
        user = graph[user_id]()
        if 'location' in user:
            return user.location
        return False

but in my tests if 'anything' in a_node always returns True.

I thought maybe I could do 'anything' in a_node.as_dict() ...but this throws Http 400 error from Facebook, I guess the unbunchify call unintentionally causes a load of weird API lookups via the getitem machinery of Graph/Node classes.

This works:

if 'location' in user.keys():
    myvar = user.location

anentropic avatar Apr 18 '11 14:04 anentropic