From fed6a01a5101a7b3c633ea3ef5a90513de39dfdd Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Thu, 5 Nov 2020 22:17:10 -0600 Subject: [PATCH] Read and write csv --- source/diff.py | 15 --------------- source/easymacro2.py | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/source/diff.py b/source/diff.py index 03779df..d3bfd3a 100644 --- a/source/diff.py +++ b/source/diff.py @@ -4724,18 +4724,3 @@ def server_smtp_test(config): return server.error -def import_csv(path, **kwargs): - """ - See https://docs.python.org/3.5/library/csv.html#csv.reader - """ - with open(path) as f: - rows = tuple(csv.reader(f, **kwargs)) - return rows - - -def export_csv(path, data, **kwargs): - with open(path, 'w') as f: - writer = csv.writer(f, **kwargs) - writer.writerows(data) - return - diff --git a/source/easymacro2.py b/source/easymacro2.py index b8cec7c..1dc2859 100644 --- a/source/easymacro2.py +++ b/source/easymacro2.py @@ -20,6 +20,7 @@ # ~ along with ZAZ. If not, see . +import csv import datetime import getpass import gettext @@ -3439,6 +3440,20 @@ class Paths(object): data = json.dumps(data, indent=4, ensure_ascii=False, sort_keys=True) return cls.save(path, data) + @classmethod + def from_csv(cls, path, args={}): + # ~ See https://docs.python.org/3.7/library/csv.html#csv.reader + with open(path) as f: + rows = tuple(csv.reader(f, **args)) + return rows + + @classmethod + def to_csv(cls, path, data, args={}): + with open(path, 'w') as f: + writer = csv.writer(f, **args) + writer.writerows(data) + return + @classmethod def copy(cls, source, target='', name=''): p, f, n, e = _P(source).info @@ -3460,6 +3475,8 @@ def __getattr__(name): return LODocs().active.active if name == 'selection': return LODocs().active.selection + if name == 'current_region': + return LODocs().active.selection.current_region if name in ('rectangle', 'pos_size'): return Rectangle() if name == 'paths': @@ -3837,4 +3854,3 @@ class LOServer(object): else: instance = self._sm.createInstance(name) return instance -