1edf4725f59ad248f3f28ac11f87819cf54b74d4
[matthijs/projects/xerxes.git] / tools / misc.py
1 """
2 Makes an iteratable object out of the given value. If value is already
3 iterable, it is simply returned. An exception is made for strings, which
4 are treated as non-iterable (It is assumed that you never want to have a
5 list of characters). For non iteratable values or strings, a list
6 containing only value is returned.
7 """
8 def make_iter(value):
9     if (not isinstance(value, basestring)):
10         try:
11             iter(value)
12             return value
13         except TypeError:
14             pass
15     return [value]
16 # vim: set sts=4 sw=4 expandtab: