-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
29 lines (26 loc) · 978 Bytes
/
utils.py
File metadata and controls
29 lines (26 loc) · 978 Bytes
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
def replace_numbers_by_variables(string):
'''
'x^2 + 2x + 1' -> 'x^[a]+[b]x+[c]'
:return: string
'''
import re
from string import ascii_lowercase
for letter in ascii_lowercase:
new = re.sub(r'([23456789]|\d{2,})', r'[{}]'.format(letter), string, 1)
if new != string: string = new
else: break
return string
import inspect
def filter_dict(dict_to_filter, thing_with_kwargs):
sig = inspect.signature(thing_with_kwargs)
filter_keys = [param.name for param in sig.parameters.values() if param.kind == param.POSITIONAL_OR_KEYWORD]
filtered_dict = {filter_key: dict_to_filter[filter_key] for filter_key in filter_keys}
return filtered_dict
def get_params_from_function(func):
return inspect.getfullargspec(func)[0]
def get_params_from_task(task):
import re
letters = re.findall(r'\[([a-zA-Z])\]', task)
return list(set(letters))
# import inspect
# return inspect.getfullargspec(func)[0]