-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathvariableCommand.py
More file actions
55 lines (47 loc) · 2.07 KB
/
variableCommand.py
File metadata and controls
55 lines (47 loc) · 2.07 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
"""
Search Variables
"""
def _vp_load_instance(var=''):
"""
load Variables with dir(globals)
"""
_VP_NOT_USING_VAR = ['_html', '_nms', 'NamespaceMagics', '_Jupyter', 'In', 'Out', 'exit', 'quit', 'get_ipython']
varList = []
query = ''
result = {}
if var == '':
varList = sorted(globals())
# result = { 'type': 'NoneType', 'list': [{'name': v, 'type': type(eval(v)).__name__} for v in _vp_vars if (not v.startswith('_')) and (v not in _VP_NOT_USING_VAR)] }
result = {'type': 'NoneType', 'list': []}
else:
varList = dir(eval(var))
query = var + '.'
# result = { 'type': type(eval(var)).__name__, 'list': [{'name': v, 'type': type(eval(var + '.' + v)).__name__} for v in _vp_vars if (not v.startswith('_')) and (v not in _VP_NOT_USING_VAR)] }
result = {'type': type(eval(var)).__name__, 'list': []}
tmpList = []
for v in varList:
try:
if (not v.startswith('_')) and (v not in _VP_NOT_USING_VAR):
tmpList.append({'name': v, 'type': type(eval(query + v)).__name__ })
except Exception as e:
continue
result['list'] = tmpList
return result
def _vp_get_type(var=None):
"""
get type name
"""
return str(type(var).__name__)
def _vp_get_variables_list(types):
"""
Get Variable list in types
"""
notUsingVariables = ['_html', '_nms', 'NamespaceMagics', '_Jupyter', 'In', 'Out', 'exit', 'quit', 'get_ipython']
notUsingTypes = ['module', 'function', 'builtin_function_or_method', 'instance', '_Feature', 'type', 'ufunc']
varList = []
searchList = globals()
if (type(types) == list) and (len(types) > 0):
varList = [{'varName': v, 'varType': type(eval(v)).__name__} for v in searchList if (not v.startswith('_')) & (v not in notUsingVariables) & (type(eval(v)).__name__ in types)]
else:
varList = [{'varName': v, 'varType': type(eval(v)).__name__} for v in searchList if (not v.startswith('_')) & (v not in notUsingVariables) & (type(eval(v)).__name__ not in notUsingTypes)]
return varList