projects
/
matthijs
/
projects
/
xerxes.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8e6aadc
)
* Add file for misc tools, now containing make_iter to ensure something is iteratable.
author
Matthijs Kooijman
<matthijs@stdin.nl>
Thu, 31 Jan 2008 16:39:33 +0000
(17:39 +0100)
committer
Matthijs Kooijman
<matthijs@stdin.nl>
Thu, 31 Jan 2008 16:39:33 +0000
(17:39 +0100)
tools/misc.py
[new file with mode: 0644]
patch
|
blob
diff --git a/tools/misc.py
b/tools/misc.py
new file mode 100644
(file)
index 0000000..
110c370
--- /dev/null
+++ b/
tools/misc.py
@@ -0,0
+1,15
@@
+"""
+Makes an iteratable object out of the given value. If value is already
+iterable, it is simply returned. An exception is made for strings, which
+are treated as non-iterable (It is assumed that you never want to have a
+list of characters). For non iteratable values or strings, a list
+containing only value is returned.
+"""
+def make_iter(value):
+ if (not isinstance(value, basestring)):
+ try:
+ iter(value)
+ return value
+ except TypeError:
+ pass
+ return [value]