python常用内置函数dir(__builtins__)#获取内置函数dir(random)#查看random中有哪些内置函数help(random.shuffle)#查看random.shuffle的用法id(a)#获取内存地址chr()#数字转为asciiord()#ascii转为数字isinstance(1,int)#判断1是否为int类型eval("1+1")#可以把字符串里的字符转换为可执行代码,但只支持一行。可以返回执行后得到的值,用于计算一
系统 2019-09-27 17:52:02 2130
Python实现Mysql数据统计的实例代码如下所示:importpymysqlimportxlwtexcel=xlwt.Workbook(encoding='utf-8')sheet=excel.add_sheet('Mysql数据库')sheet.write(0,0,'库名')sheet.write(0,1,'表名')sheet.write(0,2,'数据条数')db=pymysql.connect('192.168.1.74','root','123
系统 2019-09-27 17:51:52 2130
如下所示:#!/usr/bin/envpython#-*-coding:utf-8-*importserialimportserial.tools.list_portsport_list=list(serial.tools.list_ports.comports())iflen(port_list)<=0:print"TheSerialportcan'tfind!"else:port_list_0=list(port_list[0])port_serial
系统 2019-09-27 17:50:57 2130
首先安装一个需要用到的模块pipinstallsocial-auth-app-django安装完后在终端输入piplist会看到social-auth-app-django3.1.0social-auth-core3.0.0然后可以来我的github,下载关于滑动验证码的这个demo:https://github.com/Edward66/slide_auth_code下载完后启动项目pythonmanage.pyrunserver启动这个项目后,在主页就
系统 2019-09-27 17:50:45 2130
python批量添加的button使用同一点击事件根据传递的参数进行区分。defclear_text():print'我只是个清空而已'defclear_text(index):print'我只是个清空而已'+str(index)button=Button(framet_title,text='清空',command=clear_text)这样去设置,单个按钮对应单个点击事件没有问题的如果你是foriinRange(10):button=Button(fr
系统 2019-09-27 17:50:34 2130
python多线程#创建线程threading_list=[]t1=threading.Thread(target=music,args=(u'爱情买卖',))threading_list.append(t1)t2=threading.Thread(target=move,args=(u'阿凡达',))threading_list.append(t2)fortinthreading_list:#启动线程t.setDaemon(True)#将线程声明为守护线
系统 2019-09-27 17:50:32 2130
php调用python服务侃侃:公司用的php的popen以命令的形式调用python,首先说说这样做的缺点。php执行命令行调用python的缺点popen('pythontest.py[参数]','r');缺点一:windows默认的是gbk编码,当php中传utf-8中文参数的时候,python接收到的参数会有问题。当然,这是有解决的办法的,就是windows下转换一下字符的编码,linux不用转换。再来python接收参数的时候肯定也要转换编码了,
系统 2019-09-27 17:50:10 2130
一、往文件中写入数据往TXT文件写入的时候报错'gbk'codeccan'tencodecharacter'\xXX'inpositionXX打开文件时,增加一个选项:defwirteFile(content):path=os.getcwd()a_path=os.path.join(path,"content.txt")f=open(a_path,"w+",encoding="utf-8")f.write(content)f.close()open()中添
系统 2019-09-27 17:49:29 2130
常见的排序算法:冒泡排序,选择排序,插入排序,希尔排序,快速排序,堆排序,归并排序。冒泡排序原理:两两元素进行比较,每一趟能够确定最大元素的位置,稳定算法defbubble_sort(alist):'''冒泡排序'''#[5,4,3,2,1][4,5,3,2,1][4,3,5,2,1][4,3,2,5,1][4,3,2,1,5]n=len(alist)foriinrange(n):#count=0forjinrange(0,n-1):ifalist[j]>
系统 2019-09-27 17:49:28 2130
Python重试模块retrying工作中经常碰到的问题就是,某个方法出现了异常,重试几次。循环重复一个方法是很常见的。比如爬虫中的获取代理,对获取失败的情况进行重试。刚开始搜的几个博客讲的有点问题,建议看官方文档,还有自己动手实验。参考:https://segmentfault.com/a/1190000004085023https://pypi.org/project/retrying/最初的版本importrequestsclassProxyUtil
系统 2019-09-27 17:49:24 2130