搜索到与相关的文章
Python

python求职准备第1天—进程

进程是操作系统分配内存的最小单位Python中进程用到的库multiprocessing简单的多进程示例frommultiprocessingimportProcessfromtimeimporttime,sleepfromrandomimportrandintdefdownload_task(task_name):print(task_name+'开始下载')time=randint(1,5)sleep(time)print(task_name+f'下载

系统 2019-09-27 17:53:03 2024

Python

python检测RabbitMQ的状态是否正常的代码

将做工程过程中重要的一些代码段收藏起来,下面代码段是关于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 2024

Python

代码讲解Python对Windows服务进行监控

我们首先来看下python的全部代码,大家可以直接复制后测试:#-*-encoding:utf-8-*-importloggingimportwmiimportosimporttimefromConfigParserimportConfigParserimportsmtplibfromemail.mime.textimportMIMETextimportsocketfromdatetimeimportdatetimeimportreimportsysimp

系统 2019-09-27 17:52:12 2024

Python

[python整理]@staticmethod和@classmethod的作用

前言知识在于细节,整理很重要。在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 2024

Python

python操作日志的封装方法(两种方法)

前言今天就简单的对日志做个封装,实际工作中直接拿去用吧方法1"""------------------------------------@Time:2019/5/228:12@Auth:linux超@File:logfile.py@IDE:PyCharm@Motto:Realwarriors,daretofacethebleakwarning,daretofacetheincisiveerror!-----------------------------

系统 2019-09-27 17:51:39 2024

Python

python 使用 config 文件

在写程序时,我们经常需要定义一些路径常量,为了逻辑和代码的清晰,可以新建一个config.ini文件,然后调用其中的信息即可。config.ini文件格式如下:[section1]model_dir=/home/user/nlp-data/trained-model;注释save_input=./profiling/inputsave_state=./profiling/state......[section2]save_output=./profilin

系统 2019-09-27 17:51:24 2024

Python

【python】-----------------《外星人入侵》实现

基本功能是有一架飞机,可以通过键盘控制使其左右移动,并且喷射子弹。在飞机上方有一群外星人,也在左右移动着,被子弹击中的外星人消失。效果图如下:设计思路:1)Ship类,Bullet类,Alien类分别表示飞船,子弹,外星人的基本信息,例如飞机和外星人图像存储位置,生成子弹的位置。ship.pyimportpygameclassShip():"""docstringforship"""def__init__(self,ai_settings,screen):

系统 2019-09-27 17:51:16 2024

Python

10种经典机器学习算法——Python版

klearnpythonAPILinearRegressionfromsklearn.linear_modelimportLinearRegression#线性回归#module=LinearRegression()module.fit(x,y)module.score(x,y)module.predict(test)LogisticRegressionfromsklearn.linear_modelimportLogisticRegression#逻辑回

系统 2019-09-27 17:51:04 2024

Python

Python bsddb模块操作Berkeley DB数据库介绍

bsddb模块是用来操作bdb的模块,bdb是著名的BerkeleyDB,它的性能非常好,mysql的存储后端引擎都支持bdb的方式。这里简单介绍一些关于bsddb的使用方法。bdb不同于一般的关系数据库,它存储的数据只能是以key和value组成的一对数据,使用就像python的字典一样,它不能直接表示多个字段,当要存储多个字段的数据时,只能把数据作为一个整体存放到value中。使用bsddb面临的第一问题是使用什么数据访问方法,bdb支持四种:btre

系统 2019-09-27 17:50:30 2024

Python

python tushare 画股价走势图

pipinstalltusharestock_price.py#coding:utf-8importos,sysimportdatetimeimportmatplotlib.pyplotaspltimportpandasaspdimporttushareastsiflen(sys.argv)==2:code=sys.argv[1]else:print('usage:pythonstock_price.pystockcode')sys.exit(1)ifle

系统 2019-09-27 17:50:25 2024