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
...
使用这种方式的一个缺点就是你仍然需要去处理一些棘手的细节问题。比如,如果某些字段值被引号包围,你不得不去除这些引继续阅读 »
校园网使用PPPoE拨号上网,每次都通过图形化界面通断网络不太方便,希望能一键上网一键下线,于是写了个小脚本。
配置好相关参数后保存为 C:\Windows\System32\surf.bat ,重启命令行即可使用 surf 命令通断网络,常用的话甚至只要 win+r->enter就可以自由迅速地上线下线啦。把下面第二十行的注释去掉可以在联网同时打开ss,有些缺憾的是还没有实现断网时退出ss。
流程控制参考了Batch Guide by Terry Newton 。
```c
REM 校园网使用PPPoE拨号上网,将文件内容存为 C:\Windows\System32\surf.bat ,可以命令行拨号上网
REM 可自行加继续阅读 »