root/lib/util.py @ 446
1 |
# Useful functions and classes
|
---|---|
2 |
|
3 |
def type_name(value): return type(value).__name__ |
4 |
|
5 |
def module(value): return type(value).__module__.split('.') |
6 |
|
7 |
def root_module(value): return module(value)[0] |
8 |
|
9 |
def first(iter_): return iter_.next() |
10 |
|
11 |
def skip(iter_, func): |
12 |
# Advance iter while func is True
|
13 |
try: |
14 |
while func(iter_.curr()): iter_.next() |
15 |
except StopIteration: pass # nothing after the matching elements |
16 |
|
17 |
def rename_key(dict_, orig, new): dict_[new] = dict_.pop(orig) |