Created
March 13, 2021 14:15
-
-
Save epoz/0ece001049ace14da15ff21163628cb9 to your computer and use it in GitHub Desktop.
Textbase loader for visidata.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from visidata import Column, TableSheet | |
def open_dmp(p): | |
return TextBaseSheet(p.name, source=p) | |
class TextBaseSheet(TableSheet): | |
rowtype = "records" # rowdef: a list, of collections.OrderedDict objects | |
def iterload(self): | |
import textbase | |
for line in textbase.parse(self.source.given): | |
for col in line: | |
c = Column( | |
col, getter=lambda col, row: "\n".join(row[0].get(col.name, [])) | |
) | |
if c not in self.columns: | |
self.addColumn(c) | |
yield [line] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment