Dumps an Object's values as a formatted string. Very nicely done. Great way to display an object's member variables in human form Returns only the top-most object's variables instead of drilling down to dispolay more :param obj: The object to display :type obj: (Any) :return:
(obj)
| 20218 | |
| 20219 | # Converts an object's contents into a nice printable string. Great for dumping debug data |
| 20220 | def obj_to_string_single_obj(obj): |
| 20221 | """ |
| 20222 | Dumps an Object's values as a formatted string. Very nicely done. Great way to display an object's member variables in human form |
| 20223 | Returns only the top-most object's variables instead of drilling down to dispolay more |
| 20224 | :param obj: The object to display |
| 20225 | :type obj: (Any) |
| 20226 | :return: Formatted output of the object's values |
| 20227 | :rtype: (str) |
| 20228 | """ |
| 20229 | if obj is None: |
| 20230 | return 'None' |
| 20231 | return str(obj.__class__) + '\n' + '\n'.join( |
| 20232 | (repr(item) + ' = ' + repr(obj.__dict__[item]) for item in sorted(obj.__dict__))) |
| 20233 | |
| 20234 | |
| 20235 | def obj_to_string(obj, extra=' '): |