MCPcopy Index your code
hub / github.com/clips/pattern / save

Method save

pattern/db/__init__.py:1574–1596  ·  view source on GitHub ↗

Exports the table to a unicode text file at the given path. Rows in the file are separated with a newline. Columns in a row are separated with the given separator (by default, comma). For data types other than string, int, float, bool or None, a custom string enc

(self, path, separator=",", encoder=lambda v: v, headers=False, **kwargs)

Source from the content-addressed store, hash-verified

1572 headers = property(_get_headers, _set_headers)
1573
1574 def save(self, path, separator=",", encoder=lambda v: v, headers=False, **kwargs):
1575 """ Exports the table to a unicode text file at the given path.
1576 Rows in the file are separated with a newline.
1577 Columns in a row are separated with the given separator (by default, comma).
1578 For data types other than string, int, float, bool or None, a custom string encoder can be given.
1579 """
1580 # Optional parameters include all arguments for csv.writer(), see:
1581 # http://docs.python.org/library/csv.html#csv.writer
1582 kwargs.setdefault("delimiter", separator)
1583 kwargs.setdefault("quoting", csv.QUOTE_ALL)
1584 # csv.writer will handle str, int, float and bool:
1585 s = StringIO()
1586 w = csv.writer(s, **kwargs)
1587 if headers and self.fields is not None:
1588 w.writerows([[csv_header_encode(name, type) for name, type in self.fields]])
1589 w.writerows([[encode_utf8(encoder(v)) for v in row] for row in self])
1590 s = s.getvalue()
1591 s = s.strip()
1592 s = re.sub("([^\"]|^)\"None\"", "\\1None", s)
1593 f = open(path, "wb")
1594 f.write(BOM_UTF8)
1595 f.write(s)
1596 f.close()
1597
1598 @classmethod
1599 def load(cls, path, separator=",", decoder=lambda v: v, headers=False, preprocess=lambda s: s):

Callers 10

pushFunction · 0.45
resetFunction · 0.45
canvas.jsFile · 0.45
graph.jsFile · 0.45
test_model_saveMethod · 0.45
test_csvMethod · 0.45
test_fileMethod · 0.45
04-twitter.pyFile · 0.45
11-facebook.pyFile · 0.45
02-datasheet.pyFile · 0.45

Calls 6

csv_header_encodeFunction · 0.85
encode_utf8Function · 0.85
stripMethod · 0.80
writeMethod · 0.80
setdefaultMethod · 0.45
closeMethod · 0.45

Tested by 3

test_model_saveMethod · 0.36
test_csvMethod · 0.36
test_fileMethod · 0.36