python线程调用方式
1 直接调用import threadingimport time def sayhi(num): #定义每个线程要运行的函数 print("running on number:%s" %num) time.sleep(3) if __name__ == '__main__': t1 = threading.Thread(target=sayhi,args=(1,)) #生成一个线程实...
socket
###########################server端:import socketserver= socket.socket()server.bind(('localhost',6969))server.listen()print("等电话")conn,addr=server.accept()print(conn,addr)print("来了")data = conn.recv(1024)print("recv:",data)conn.send(data.upper())server.close()#################...
类
类名大写!!!class dog(object): def __init__(self,name): self.NAME=name def sayhi(self): print("hello, I am a dog.my name is:",self.NAME) def eat(self,fo...
不同目录间模块调用
### 程序结构:```shopping_atm/|-- shopping/| |-- __init__.py| |-- shopping.py| |-- user_info| |-- zhangfeilast_buy||-- atm/| |-- __init__.py| |-- main.py | |-- bin/| &n...
python备份文件及写入新内容
def oper_file(file_name,lines): ##备份旧文件,将更改的内容写入新文件 old_file=file_name now = datetime.datetime.now().strftime("%Y%m%d%H%M") newfile=old_file+"_bk_"+now shutil.copyfile(old_file,newfile) new_conf = open(file_name, 'w+') new_conf.writelines(lines) new_conf.fl...
re模块
常用正则表达式符号:'.' 默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行'^' 匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r"^a","\nabc\neee",flags=re.MULTILINE)'$' 匹配字符结尾,或e.se...
shutil模块
shutil模块import shutil f1 = open("hello.py")f2 = open("bb.py","w")#shutil.copyfileobj('c:\0000\00.py','c:\bb.py')shutil.copyfileobj(f1,f2) ##Copy the contents of the file-like object fsrc to the file-like object fdst 只能复制文件,需要先open文件shutil.copyfile("c:\\0000\\00.py","C:\...
python生成器
生成器 只有在调用时才会生成相应的数据只有一个__next__()方法。 next()a= (i for in in range(1000))a.__next__()将函数中的print() 换成yield后,则变成了一个生成器:def fib(max): n,a,b= 0,0,1 while n < max: yie...
python修改文件的几点想法
这几天在琢磨用python修改文件,有点小想法和大家分享。1 操作前备份文件。2 将文件内容利用readlines读入一个列表。3 将部分关键字和它的相关行写入一个字典。4 增删改时不一定对最小的单位更改,越小越麻烦,可以直接要求写入一完整行,然后对输入的行利用split进行list,对比操作。5 增删改操作完成后,就是...
用python生成ogg的mapcol参数
源表和目标表结构不一致,源表列比目标表多。1 需要配对的列名称:LIST_IDSTATUSREAL_NAMEREASONPERSON_TYPEAGENT_IDCUSTOMER_IDSOURCE_TYPED...
局部&全剧变量
示例1:def test1(x,y=4): print("x =",x) print("y =",y) return 0x = 5test1(3,2)print(x)##############执行结果为:x=3y=25#########该程序中,函数中的x属于局部变量。示例2:def test1(x,y=4): global a ...
函数
函数内部有三部分:1 介绍描述。2 代码块,处理逻辑。3 返回值。过程是没有返回值的函数。def func1(): '''函数''' print("hello world") return 0def func2(): '''过程''' print("hello world") ...
集合
集合特点:没有重复值;无序;交集:list1 = {1,2,3,1,2,4}list2 = {3,5,4}list2.intersection(list1))print(list1 & list2)并集:list1.union(list2)print(list1 | list2)差集(list1中有list2没有的):list1.difference(list2)print(list1 - list2)子集,判断list1是否是list2的子集:list1.iss...
文件操作
文件操作打开文件:f = open("how.txt")关闭文件:f.close()读文件:f.read()打开模式:f = open("how.txt",'r') #读f = open("how.txt",'w') #写,会清空原内容然后写入f = open("how.txt",'a') #追加f = open("how.txt",'r+') #读写模式f = open("how.txt",'w+') #写读模式,先清空...
字符编码转换
字符编码转换gbk -----decode------> unicode------encode-----> utf8GBK转为utf8的流程:1 通过编码decode转为unicode。2 通过encode转为utf-8例,将gbk的str_gbk转为utf8的gbk_to_utf8:str_gbk="hello"1 gbk_to_unicode=str_gbk.decode("gbk")2 gbk_to_utf8=gbk_to_unicode.encode("utf8")即:gbk_to_utf8=s...
输出格式化
有4种方法。方法1:#############name = input("name:",)age = input("age:",)job = input("job:",)info = '''---- info of {_a} ---name:{_a}age:{_b}job:{_c}''' .format(_a=name,_b=age,_c=job)pring(info)方法2:##############name = input("name:",)...
gh-ost测试
环境master: 10.0.0.11 vm1 3307slave: 10.0.0.12 vm2 3307一 下载&&安装到 https://github.com/github/gh-ost/releases直接下载编译好的binary包。如;gh-ost-binary-linux-20160815105421.tar.gz上传到服务器,如slave。解压。二 测试测试一:连接到从库,在主库做变更。这是gh-ost 默认的工作方式。...
5.6升级到5.7.13后,开启多源复制,遇到重复的channel name
一共三个数据库,原版本均为5.6,升级到5.7.13后开启多源复制,做成两主一从,发现channel name同名。在从库执行reset slave all后,从库自动重启。5.6 ---> 5.7.13:5.6:1 cd /usr/local/mysql ; scripts/mysql_install_db --user=mysql --defaults-file=/57data/my56.cnf2 /usr/local/mysql/bin/mysqld_safe --defau...
Error message file '/usr/local/mysql/share/english/errmsg.sys' had only 886
Error message file '/usr/local/mysql/share/english/errmsg.sys' had only 886根据错误提示,发现是errmsg.sys文件和升级后的软件版本不一致导致。解决:1) cp /usr/share/mysql/english/errmsg.sys/usr/share/mysql/english/errmsg.sys.backup2) 下载mysql-5.7.13.tar.gz3) tar -xzvf mysql-5.7...
Warning | 1292:Truncated incorrect binlog_cache_size value:
binlog_cache_size的大小必须为pagesize的倍数,不然会有一个warning, “Warning | 1292 | Truncated incorrect binlog_cache_size value: '33792'”,然后向下取最接近n个pagesize的值。mysql> set global binlog_cache_size=1024*1;Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> show warnings;+-------...