前言知识在于细节,整理很重要。在python中,有3类方法:1)静态方法(staticmethod)2)类方法(classmethod)3)实例方法其中静态方法和类方法是不需要进行实例就可以直接调用,语法格式:类名.方法名具体举个例子说明deffunc(x):print("hello,我是常用方法")classFun:deffunc1(self,x):print("hello,我是类中方法",x,self)@classmethoddeffunc2(cls,
系统 2019-09-27 17:51:55 2038
步骤:1.掌握几种对象及其关系2.了解每类对象的基本操作方法3.通过转化关系转化涉及对象1.datetime>>>importdatetime>>>now=datetime.datetime.now()>>>nowdatetime.datetime(2018,1,12,23,9,12,946118)>>>type(now)2.timestamp>>>importtime>>>time.time()1421075455.5682433.timetuple>>
系统 2019-09-27 17:51:17 2038
pythonredis连接有序集合去重的代码如下所述:#-*-coding:utf-8-*-importredisfromconstantimportredis_ip,redis_db,redis_pw,redis_zset_namepool=redis.ConnectionPool(host=redis_ip,db=redis_db,password=redis_pw)#pool=redis.ConnectionPool(db=6,password=re
系统 2019-09-27 17:51:00 2038
如下所示:#!/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 2038
随机整数:复制代码代码如下:>>>importrandom>>>random.randint(0,99)21随机选取0到100间的偶数:复制代码代码如下:>>>importrandom>>>random.randrange(0,101,2)42随机浮点数:复制代码代码如下:>>>importrandom>>>random.random()0.85415370477785668>>>random.uniform(1,10)5.4221167969800881
系统 2019-09-27 17:50:23 2038
python初学小记使用PyCharm向世界打招呼!print(“Helloworld!”)介绍自己的基本信息的方法name=input("name:")age=int(input("age:"))#integer强转义成数字print(type(age),type(str(age)))job=input("job:")salary=input("salary:")#一.info='''-------infoof%s--------Name:%sAge:%
系统 2019-09-27 17:49:39 2038
withopen("1.txt")asf:whileTrue:line=f.readline()ifnotline:break;print(line.rstrip())
系统 2019-09-27 17:48:48 2038
问题提出:有时候我们采集网页,处理完毕后将字符串保存到文件或者写入数据库,这时候需要制定字符串的编码,如果采集网页的编码是gb2312,而我们的数据库是utf-8的,这样不做任何处理直接插入数据库可能会乱码(没测试过,不知道数据库会不会自动转码),我们需要手动将gb2312转换成utf-8。首先我们知道,python里的字符默认是ascii码,英文当然没问题啦,碰到中文的时候立马给跪。不知道你还记不记得,python里打印中文汉字的时候需要在字符串前面加u
系统 2019-09-27 17:48:17 2038
在使用uliweb开发soapwebservice后,启动uliweb时,werkzeug的日志莫名其妙丢失了。正常的日志:复制代码代码如下:[INFO]*LoadingDebuggedApplication...[INFO]*Runningonhttp://localhost:8000/[INFO]*Restartingwithreloader[INFO]*LoadingDebuggedApplication...异常的日志:复制代码代码如下:[INFO
系统 2019-09-27 17:48:08 2038
有很久没有更新我的博客了,在学习flask去了,别人都说flask不难,其实现在我也这么觉得,但是在刚接触的时候还是有点吃力的。在学习的过程中查阅了不少,也了解了许多,今天想做个总结。。。以免觉得学了那么久什么都没学到,还有防止以后忘记。一.关于装饰器,路由最开始接触的时候觉得好神奇,只会照着敲不知道怎么自己用起来@app.route(‘/')defhello:print(‘hello')注意:1.只有@这个东西是固定的,app是可以换的,这与蓝本中的定义
系统 2019-09-27 17:48:05 2038