brennerm / PyTricks

Collection of less popular features and tricks for the Python programming language
MIT License
3.07k stars 503 forks source link

Initial commit #30

Closed betezed closed 9 years ago

brennerm commented 9 years ago

Why not just use obj().attr ?

betezed commented 9 years ago

Sometimes, you need to access some attributes with variables containing the attribute's name, instead of accessing it directly (sorry for my english, btw) For exemple :

class obj():
    attr = 1
def getkey(obj, key):
    return obj().key
print(getkey(obj(), "attr")) # Output : AttributeError: obj instance has no attribute 'key'
brennerm commented 9 years ago

Please append the ".py" suffix to your file and add yourself to the contributors.