Version:Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
文件与I/O
读写文本数据
使用带有rt模式的open()函数读取文本文件
```python
with open('test.csv', mode='rt', encoding='utf-8') as f:
data = f.read()
print(data)
with open('test.csv', mode='rt', encoding='utf-8') as f:
for line in继续阅读 »
Version:Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
There are two ways of constructing a software design: one way is to make it so simple that there are obviously no deficiences; the other is to make it so complicated that there are no obvious deficiences.
---- C.A.R.继续阅读 »
开发环境:Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
自序
也许你会说,我为什么要学习使用CSV模块呢?没有CSV模块我一样可以解析操作CSV文件,比如下面这种代码:
python
with open('stocks.csv') as f:
for line in f:
row = line.split(',')
# process row
...
使用这种方式的一个缺点就是你仍然需要去处理一些棘手的细节问题。比如,如果某些字段值被引号包围,你不得不去除这些引继续阅读 »