classRoom:def__init__(self,name,length,width):self.__name=nameself.__length=lengthself.__width=widthdefget_name(self):returnself.__namedefset_name(self,newName):iftype(newName)isstrandnewName.isdigit()==False:self.__name=newNameel
系统 2019-09-27 17:53:27 1981
阅读更多1,下载pip安装包pip-19.1.1.tar.gz;2,解压缩后出现setup.py文件,然后在目录中通过Shift+右击,点击在此处打开命令窗口,通过pythonsetup.pyinstall,进行安装;3,安装后,通过cmd窗口中,输入piplist,查看命令是否起作用;4,使用pipinstall-Upip,对pip进行升级;5,使用pipinstallpsycopg2,安装postgresql数据驱动;注意:1,python不要装在c盘
系统 2019-09-27 17:53:05 1981
一.什么是图片懒加载?-案例分析:抓取站长素材http://sc.chinaz.com/中的图片数据#!/usr/bin/envpython#-*-coding:utf-8-*-importrequestsfromlxmlimportetreeif__name__=="__main__":url='http://sc.chinaz.com/tupian/gudianmeinvtupian.html'headers={'User-Agent':'Mozill
系统 2019-09-27 17:52:42 1981
将做工程过程中重要的一些代码段收藏起来,下面代码段是关于python检测RabbitMQ的状态是否正常的代码。importsocketdefcheck_aliveness(ip,port):sk=socket.socket(socket.AF_INET,socket.SOCK_STREAM)sk.settimeout(1)try:sk.connect((ip,port))print'serviceisOK!'returnTrueexceptExceptio
系统 2019-09-27 17:52:41 1981
填充螺旋演示结果:实例代码:importmatplotlib.pyplotaspltimportnumpyasnptheta=np.arange(0,8*np.pi,0.1)a=1b=.2fordtinnp.arange(0,2*np.pi,np.pi/2.0):x=a*np.cos(theta+dt)*np.exp(b*theta)y=a*np.sin(theta+dt)*np.exp(b*theta)dt=dt+np.pi/4.0x2=a*np.cos
系统 2019-09-27 17:52:35 1981
一、安装MySQL-python复制代码代码如下:#yuminstall-yMySQL-python二、打开数据库连接复制代码代码如下:#!/usr/bin/pythonimportMySQLdbconn=MySQLdb.connect(user='root',passwd='admin',host='127.0.0.1')conn.select_db('test')cur=conn.cursor()三、操作数据库复制代码代码如下:definsertdb(
系统 2019-09-27 17:52:20 1981
作为eclipse的忠实粉丝,我自然乐意用eclipse来编写。于是捣鼓了一小会儿就搞好了。但是我运行的第一个程序出现了一个很奇怪的问题:SyntaxError:(unicodeerror)‘utf-8’codeccan’tdecodebyte0xceinposition16:invalidcontinuationbyte我隐约的看到了utf-8,知道了肯定是编码的问题,可是我寻思我没有写汉字呀原来是自动生成的日期中有中文。删掉就好了。但是如果我们真的需要
系统 2019-09-27 17:52:01 1981
如下所示:#!/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 1981
代理ProxyHandler处理器(代理)1、代理的原理:在请求目的网站之前,先请求代理服务器,然后让代理服务器去请求目的网站,代理服务器拿到目的服务器的网站数据后,再转发给我们的代码。2、http://httpbin.org/ip这个网站可以方便我们查看一些http请求参数3、使用代理的方法:ProxyHandle这个方法需要传入一个字典,key:请求schema,value:代理服务器ip+端口fromurllibimportrequest##url=
系统 2019-09-27 17:50:55 1981
類別定義class類別名:例如:>>>classPoint:...x=0.0...y=0.01.宣告>>>p1=Point()>>>p1.x,p1.y(0.0,0.0)2.賦値>>>p1.x=5.0>>>p1.y=6.0>>>p1.x,p1.y(5.0,6.0)3.位址指向>>>p1<__main__.Pointobjectat0x00000000021B22E8>>>>id(p1.x)30060832>>>id(p1.y)300608084.別名Alia
系统 2019-09-27 17:50:30 1981