Day6_python(基础知识)

f=open("yesterday2",'r',encoding="utf-8")
f_new = open("yesterday2.bak","w",encoding="utf-8")
for line in f:
if "xxx" in line :
line = line.replace("xxx","xxx+1")

f_new.write(line)


import sys
find_str = sys.argv[1]
replace_str = sys.argv[2]


with open #(不需要关闭,自动关闭文件)
with open("yesterday2",'r',encoding="utf-8") as f:

for line in f:
print(line) #一行代码不能超过80个字符

作业:
实现简单的shell sed 替换功能
修改haproxy配置文件


字符编码与转换:

Ascii 1个字节
Unicode 中文两个字节

utf-8 #所有的英文是Ascii一个字节,中文还是Unicode三个字节

 

s_to_gbk.decode("gbk").encode("utf-8")


#-*-coding:gbk-*-


#-*-coding:gbk-*-

面向对象------》类-----》class
面向过程 -----》过程-----》def
函数式编程-----》函数----》def


import time
def logger():
time_format = '%Y-%m-%d %x'
time_current=time.strftime(time_format)
with open('a.txt,'a+') as f:
f.write('%s end action\n' %time_current)

 

转载于:https://www.cnblogs.com/huyong5/p/6597762.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值