1
2
3
4
5
6 """
7 :mod:`edPDB.utilities` -- Helper functions and classes
8 ========================================================
9
10 The module defines some convenience functions and classes that are
11 used in other modules
12
13
14 Functions
15 ---------
16
17 Functions that improve list processing and which do *not* treat
18 strings as lists:
19
20 .. autofunction:: iterable
21 .. autofunction:: asiterable
22
23 """
24
25
27 """Returns ``True`` if *obj* can be iterated over and is *not* a string."""
28 if type(obj) is str:
29 return False
30
31 if hasattr(obj, 'next'):
32 return True
33 try:
34 len(obj)
35 except TypeError:
36 return False
37 return True
38
40 """Returns obj so that it can be iterated over; a string is *not* treated as iterable"""
41 if not iterable(obj):
42 obj = [obj]
43 return obj
44