bit、Byte、bps、Bps、pps、Gbps的单位详细说明及换算
2012-07-24 17:04
176 查看
为了避免打开文件后忘记关闭,可以通过管理上下文,即:
如此方式,当with代码块执行完毕时,内部会自动关闭并释放文件资源。
以往我们打开文件一般用如下方法:
如果运用with,则可以将上述代码改写为:
另外在Python2.7之后支持能同时打开多个文件,即:
示例代码:(修改配置文件)
后面再继续check 测试,如果测试通过,则可以将log1改名为log1.bak,log2改名为log1,这样就完成了
配置文件的修改
本文出自 “平平淡淡才是真” 博客,请务必保留此出处http://ucode.blog.51cto.com/10837891/1719396
with open('log','r') as f: f.write('xxxxxx') f.readlines() ...................
如此方式,当with代码块执行完毕时,内部会自动关闭并释放文件资源。
以往我们打开文件一般用如下方法:
obj = open('log','r') obj.write('abcdefg') obj.close()
如果运用with,则可以将上述代码改写为:
with open('log','r') as f: f.write('abcdefg') f.readlines()
另外在Python2.7之后支持能同时打开多个文件,即:
with open('file1','r') as obj1,open('file2','w') as obj2
示例代码:(修改配置文件)
with open('log1','r') as obj1, open('log2','w') as obj2: for line in obj1: new_line = line.replace('10.0.0.10','10.0.0.100') obj2.write(new_line)
后面再继续check 测试,如果测试通过,则可以将log1改名为log1.bak,log2改名为log1,这样就完成了
配置文件的修改
本文出自 “平平淡淡才是真” 博客,请务必保留此出处http://ucode.blog.51cto.com/10837891/1719396
相关文章推荐
- bit、Byte、bps、Bps、pps、Gbps的单位详细说明及换算
- bit、Byte、bps、Bps、pps、Gbps的单位详细说明及换算
- bit、Byte、bps、Bps、pps、Gbps的单位详细说明及换算
- bit、Byte、bps、Bps、pps、Gbps的单位详细说明及换算
- bit、Byte、bps、Bps、pps、Gbps的单位详细说明及换算
- bit、Byte、bps、Bps、pps、Gbps的详细说明及换算
- bit、Byte、bps、Bps、pps、Gbps的详细说明及换算
- 萌新扫盲8—bit、Byte、bps、Bps、pps、Gbps详细说明及换算
- bit、Byte、bps、Bps、pps、Gbps的详细说明及换算
- bit、Byte、bps、Bps、pps、Gbps的详细说明及换算
- bit、Byte、bps、Bps、pps、Gbps单位详细解释
- bit、Byte、bps、Bps、pps、Gbps的详细说明
- bit,Byte,bps,Bps,pps,Gbps的详细说明
- bit、Byte、bps、Bps、pps单位详解
- bit、Byte、bps、Bps、pps的详细介绍
- bit、位、byte、B、字节、字符等换算
- 计算机存储单位:bit, Byte, KB, MB, GB, TB, PB, EB, ZB, BB
- 【C++】Byte/KB/MB/GB/TB/PB/EB 单位换算C++代码
- Android-布局单位以及布局详细说明
- Byte、bit、bps、Bps详解