forked from zhanghe06/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_csv.py
More file actions
37 lines (29 loc) · 734 Bytes
/
test_csv.py
File metadata and controls
37 lines (29 loc) · 734 Bytes
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
33
34
35
36
37
# encoding: utf-8
__author__ = 'zhanghe'
import csv
def test_read(file_name):
"""
测试读CSV文件
:param file_name:
:return:
"""
with open(file_name, 'rb') as csv_file:
spam_reader = csv.reader(csv_file)
for row in spam_reader:
print '\t'.join(row)
return [i for i in spam_reader]
def test_write(file_name):
"""
测试写CSV文件
:param file_name:
:return:
"""
with open(file_name, 'ab') as csv_file:
spam_writer = csv.writer(csv_file)
spam_writer.writerow(['淘宝', 54, 'E'])
if __name__ == '__main__':
filename = 'eggs.csv'
# test_read(filename)
# test_write(filename)
print '\n'
test_read(filename)