python读取csv文档
来源:互联网 发布:淘宝能赚多少钱 编辑:程序博客网 时间:2024/06/14 09:03
- 写入并生成csv文件
代码:
import csv
csvfile = file(‘csv_test.csv’, ‘wb’)
writer = csv.writer(csvfile)
writer.writerow([‘姓名’, ‘年龄’, ‘电话’])
data = [
(‘小河’, ‘25’, ‘1234567’),
(‘小芳’, ‘18’, ‘789456’)
]
writer.writerows(data)
csvfile.close()
wb中的w表示写入模式,b是文件模式
写入一行用writerow
多行用writerows
- 读取csv文件
代码:
import csv
csvfile = file(‘csv_test.csv’, ‘rb’)
reader = csv.reader(csvfile)
for line in reader:
print line
csvfile.close()
运行结果:
root@he-desktop:~/python/example# python read_csv.py
[‘\xe5\xa7\x93\xe5\x90\x8d’, ‘\xe5\xb9\xb4\xe9\xbe\x84’, ‘\xe7\x94\xb5\xe8\xaf\x9d’]
[‘\xe5\xb0\x8f\xe6\xb2\xb3’, ‘25’, ‘1234567’]
[‘\xe5\xb0\x8f\xe8\x8a\xb3’, ‘18’, ‘789456’]
0 0
- python读取csv文档
- python网络爬虫文档读取-CSV文件
- python 循环读取txt文档 并转换成csv
- python 读取csv文档hex字符串 转为int并存储
- Python--读写CSV文档
- Python--读写CSV文档
- Python 读写CSV文档
- Python-读取csv文件
- python读取CSV文件
- python 读取CSV 文件
- Python读取CSV文件
- Python读取CSV文件
- Python读取上证指数csv
- python 读取csv
- python读取csv文件
- python 读取csv文件
- python读取csv
- python读取csv文件
- JavaScript入门(五) - 关闭窗口(window.close)
- org.hibernate.hql.internal.ast.QuerySyntaxException: FwbzItem is not mapped
- gcc/g++编译命令与使用
- 一个优秀的Java程序员必须了解GC的工作原理
- [C++] LeetCode #6 ZigZag Conversion
- python读取csv文档
- 使用Fiddler抓取数据包 安装配置
- printf 输出格式设置
- jsp页面截取字符串
- Eclipse log4j.xml – log4j.dtd cannot be validated as the XML definition
- dpdk相关连接
- Java基础4--数组
- Linux初学者需要掌握的命令
- java算法2~求字符串中的数字字串的求和