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