changeset 317:de23e595bb5c

experiments with line flattening
author cat@eee
date Thu, 11 Feb 2010 09:08:22 -0500
parents 8a76f597d2f9
children f44ad8de0d17
files cmd2.py flatten_lines.py
diffstat 2 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Wed Feb 10 19:44:27 2010 -0500
+++ b/cmd2.py	Thu Feb 11 09:08:22 2010 -0500
@@ -425,6 +425,10 @@
         self.shortcuts = sorted(self.shortcuts.items(), reverse=True)
         self.keywords = self.reserved_words + [fname[3:] for fname in dir(self) 
                                                if fname.startswith('do_')] 
+        import pdb; pdb.set_trace()
+        def linelist(arg):
+            result = []
+            
         self.settable = (l.strip() for l in self.settable if l.strip())
         self.settable = dict(ljust(l.split(None,1), 2, '') for l in self.settable)
         self.doubleDashComment = pyparsing.NotAny(pyparsing.Or(options_defined)) + pyparsing.Literal('--') + pyparsing.restOfLine        
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flatten_lines.py	Thu Feb 11 09:08:22 2010 -0500
@@ -0,0 +1,15 @@
+import doctest
+def flatten(texts):
+    '''
+    >>> flatten([['cow', 'cat'], '', 'fish', ['bird']])
+    ['cow', 'cat', 'fish', 'bird']
+    '''
+    result = []
+    if isinstance(texts, basestring):
+        result.extend(texts.splitlines())
+    else:
+        for text in texts:
+            result.extend(flatten(text))
+    result = [r.strip() for r in result if r.strip()]
+    return result
+doctest.testmod()