-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdev_utilities.py
More file actions
59 lines (48 loc) · 2.24 KB
/
dev_utilities.py
File metadata and controls
59 lines (48 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# _ __ _ ___ _ ___ _ _
# | |/ /_ _ __ _| |_ ___ __/ __| __ _| |___ _ __ ___| _ \ |_ _ __ _(_)_ _
# | ' <| '_/ _` | _/ _ (_-<__ \/ _` | / _ \ ' \/ -_) _/ | || / _` | | ' \
# |_|\_\_| \__,_|\__\___/__/___/\__,_|_\___/_|_|_\___|_| |_|\_,_\__, |_|_||_|
# |___/
# License: BSD License ; see LICENSE
#
# Main authors: Philipp Bucher (https://github.com/philbucher)
#
# This file contains a collection of functionalities that are useful for developing / debugging but should not be used in production
# python imports
import sys
def PrintObjectInfo(label, obj, print_python_methods=False):
# function to print all methods of an object
# very useful to see what the objects of salome have to offer
sys.stdout.flush()
print('\nPrinting information for object "{}" of type: {}'.format(label, type(obj)))
print('Methods:')
methods = [m for m in dir(obj) if not m.startswith('__') and callable(getattr(obj,m))]
for method in sorted(methods):
print('\t' + str(method))
print('\nAttributes:')
attributes = [a for a in dir(obj) if not a.startswith('__') and not callable(getattr(obj,a))]
attributes_by_type = {}
for attribute in sorted(attributes):
attr_type = str(type(getattr(obj,attribute)))
if attr_type not in attributes_by_type:
attributes_by_type[attr_type] = []
attributes_by_type[attr_type].append(attribute)
sorted_types = sorted(list(attributes_by_type.keys()))
for attr_type in sorted_types:
print("\tType:", attr_type)
for attr in attributes_by_type[attr_type]:
print("\t\t", attr)
print()
if print_python_methods:
print('\nPYTHON Methods:')
methods = [m for m in dir(obj) if m.startswith('__') and callable(getattr(obj,m))]
for method in sorted(methods):
print('\t' + str(method))
print('\nPYTHON Attributes:')
attributes = [a for a in dir(obj) if a.startswith('__') and not callable(getattr(obj,a))]
for attribute in sorted(attributes):
print('\t' + str(attribute))
sys.stdout.flush()
def print_with_flush(*args):
print(args)
sys.stdout.flush()