关于元组,上一讲中涉及到了这个名词。本讲完整地讲述它。先看一个例子:>>>#变量引用str>>>s="abc">>>s'abc'>>>#如果这样写,就会是...>>>t=123,'abc',["come","here"]>>>t(123,'abc',['come','here'])上面例子中看到的变量t,并没有报错,也没有“最后一个有效”,而是将对象做为一个新的数据类型:tuple(元组),赋值给了变量t。元组是用圆括号括起来的,其中的元素之间用逗号隔开。
系统 2019-09-27 17:56:37 2270
使用scipy.signal的argrelextrema函数(API),简单方便importnumpyasnpimportpylabasplimportmatplotlib.pyplotaspltimportscipy.signalassignalx=np.array([0,6,25,20,15,8,15,6,0,6,0,-5,-15,-3,4,10,8,13,8,10,3,1,20,7,3,0])plt.figure(figsize=(16,4))plt
系统 2019-09-27 17:56:11 2270
csv以逗号分隔,但是我发现我写的文件里出现多列跟逗号没关系,就算去除了逗号也还是一样。#!/usr/bin/envpython#-*-coding:utf8-*-#@TIME:2019/5/1813:39#@Author:17976#@File:piplines.py#@Description:importreimportpymongofrompymongo.errorsimportDuplicateKeyErrorimportsettingsclass
系统 2019-09-27 17:55:51 2270
Timer继承子Thread类,是Thread的子类,也是线程类,具有线程的能力和特征。这个类用来定义多久执行一个函数。它的实例是能够延迟执行目标函数的线程,在真正执行目标函数之前,都可以cancel它。Timer源码:classTimer(Thread):def__init__(self,interval,function,args=None,kwargs=None):Thread.__init__(self)self.interval=interval
系统 2019-09-27 17:54:46 2270
本文实例主要向大家分享了一个Python+matplotlib+numpy绘制精美的条形统计图的代码,效果展示如下:完整代码如下:importmatplotlib.pyplotaspltfromnumpyimportarangefromnumpy.randomimportranddefgbar(ax,x,y,width=0.5,bottom=0):X=[[.6,.6],[.7,.7]]forleft,topinzip(x,y):right=left+wid
系统 2019-09-27 17:52:47 2270
pip安装matplotlib没有能成功,打印出错误BeginningwithMatplotlib3.1,Python3.6oraboveisrequired原因本地环境是python3.6以下的版本。解决如果不升python版本的话,降低要安装的matplotlib版本。出现这个问题,安装的版本应该是matplotlib3.1试着降低版本pipinstallmatplotlib==3.0用国内源的话pipinstall-ihttps://pypi.tun
系统 2019-09-27 17:52:44 2270
一、序列类型(字符串,元组(),列表[])序列类型支持in,len(),分片[],迭代,5种内置序列类型:bytearray,bytes,list,str,tuple(元组)。1、元组可以嵌套(如:x=str[2][1][0][1])2、元组的命名(collections.namedtuple(),即自定义)样:sale=collctions.namedtuple("sale","productidcustomeriddateprice")逗号前的为元组类
系统 2019-09-27 17:52:31 2270
如下所示:#!/usr/bin/python#coding:utf-8importMySQLdbimporttime,datetime#zabbix数据库信息:zdbhost='172.16.8.200'zdbuser='zabbix'zdbpass='zabbix'zdbport=3306zdbname='zabbix'#生成文件名称:xlsfilename='zabbix.xls'#需要查询的key列表[名称,表名,key值,取值,格式化,数据整除处理
系统 2019-09-27 17:51:12 2270
这篇文章主要介绍threading模块中的主类Thread的一些主要方法,实例代码如下:复制代码代码如下:'''Createdon2012-9-7@author:walfred@module:thread.ThreadTest3@description:'''importthreadingclassMyThread(threading.Thread):def__init__(self):threading.Thread.__init__(self)defr
系统 2019-09-27 17:50:58 2270
思路是10/16进制的转换和字符串的处理开始造轮子1、判断是否是mac地址正则匹配是否符合条件1importre23defisMac(string):4preg=re.compile('^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$')5ret=preg.match(string)6ifretisNone:7returnFalse8else:9returnTrue2、mac转int替换掉冒号转16进制1defmacToInt(ma
系统 2019-09-27 17:49:03 2270