2013-12-02 19:23:22 -05:00
|
|
|
import collections
|
|
|
|
|
|
|
|
def flat_iteration(l):
|
|
|
|
for element in l:
|
|
|
|
if isinstance(element, collections.Iterable):
|
|
|
|
for element2 in flat_iteration(element):
|
|
|
|
yield element2
|
|
|
|
else:
|
|
|
|
yield element
|
|
|
|
|
2013-11-02 11:03:47 -04:00
|
|
|
def xdir(obj, return_values=False):
|
|
|
|
for attr in dir(obj):
|
|
|
|
if attr[:2] != "__" and attr[-2:] != "__":
|
|
|
|
if return_values:
|
|
|
|
yield attr, getattr(obj, attr)
|
|
|
|
else:
|
|
|
|
yield attr
|
2013-12-01 11:56:07 -05:00
|
|
|
|
|
|
|
def autotype(s):
|
|
|
|
if s == "True":
|
|
|
|
return True
|
|
|
|
elif s == "False":
|
|
|
|
return False
|
|
|
|
try:
|
|
|
|
return int(s, 0)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
return s
|