Read and write csv

This commit is contained in:
Mauricio Baeza 2020-11-05 22:17:10 -06:00
parent c0e246bb35
commit fed6a01a51
2 changed files with 17 additions and 16 deletions

View File

@ -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

View File

@ -20,6 +20,7 @@
# ~ along with ZAZ. If not, see <https://www.gnu.org/licenses/>.
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