forked from decaff42/python_yfs_library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_export_file.py
32 lines (24 loc) · 888 Bytes
/
func_export_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
__version__ = "20200229"
__author__ = "Decaff_42"
__copyright__ = "2020 by Decaff_42"
__license__ = """Only non-comercial use with attribution is allowed without
prior written permission from Decaff_42."""
import os
import csv
def write_csv(path, data):
"""Write a csv file to the specified path with list of list data"""
with open(path, 'w', newline='') as csv_file:
writer = csv.writer(csv_file)
writer.writerows(data)
def write_txt(path, data):
"""write a plain text file to the specified path with list of list data"""
with open(path, 'w') as txt_file:
for row in data:
try:
if row.endswith("\n") == False:
txt_file.write('{}\n'.format(row))
else:
txt_file.write(row)
except:
print(row)