Example #1
0
 def toStr(self, obj):
     result = None
     if not AIUtils.isEmpty(obj):
         attrs = dir(obj)
         result = []
         for attr in attrs:
             if attr.startswith('get'):
                 prop = AIStrUtils.toLowerF(attr[3:])
                 func = getattr(obj, attr)
                 value = apply(func, [])
                 # 判断类型,不同的字符串转换方式
                 propValue = AIUtils.list2str(value) if AIUtils.isList(value) \
                 else AIUtils.dict2str(value) if AIUtils.isDict(value) \
                 else ('\'' + AIUtils.toStr(value) + '\'') if AIUtils.isStr(value) \
                 else AIUtils.toStr(value)
                 result.append('\'' + prop + '\':' + propValue + '')
         result = '{' + ','.join(result) + '}'
     else:
         raise Exception('input parameter type not correct!')
     
     return result