Created
June 11, 2012 15:00
-
-
Save ahinz/2910499 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getqattr(obj, name): | |
''' get value of an object, safely ''' | |
try: | |
if hasattr(name,'__call__'): | |
return name(obj) | |
else: | |
value = getattr(obj, name) | |
if hasattr(value, '__call__'): # function generated value | |
if name.find('link') != -1: # link tuple triplet | |
return _linkify(value()) | |
return value() | |
elif (isinstance(value, datetime.datetime) | |
or isinstance(value, datetime.date)): # datetime object | |
return datetime2iso8601(value) | |
return value | |
except: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment