From 9585fef332d3fbc49bd47fbb098d86d318d9b390 2012-09-14 21:43:39 From: Greg Caporaso Date: 2012-09-14 21:43:39 Subject: [PATCH] improved behavior of FileLinks.__repr__ to be more like the behvior of _repr_html_ --- diff --git a/IPython/lib/display.py b/IPython/lib/display.py index 4e9421e..4b7300d 100644 --- a/IPython/lib/display.py +++ b/IPython/lib/display.py @@ -4,7 +4,7 @@ Authors : MinRK, gregcaporaso """ from os import walk -from os.path import exists, isfile, splitext, abspath +from os.path import exists, isfile, splitext, abspath, join class YouTubeVideo(object): @@ -91,7 +91,7 @@ class FileLink(object): return self._format_path() def __repr__(self): - """return path to file + """return absolute path to file """ return abspath(self.path) @@ -149,3 +149,17 @@ class FileLinks(FileLink): self.html_link_str % (fp,fn), self.result_html_suffix])) return '\n'.join(result_entries) + + def __repr__(self): + """return newline-separated absolute paths + """ + result_entries = [] + for root, dirs, files in walk(self.path): + for fn in files: + fp = abspath(join(root,fn)) + # if all files are being included, or fp has a suffix + # that is in included_suffix, create a link to fp + if self.included_suffixes == None or \ + splitext(fn)[1] in self.included_suffixes: + result_entries.append(fp) + return '\n'.join(result_entries) \ No newline at end of file