搜索到与相关的文章
Python

python连接PostgreSQL数据库的过程详解

1.常用模块#连接数据库connect()函数创建一个新的数据库连接对话并返回一个新的连接实例对象PG_CONF_123={'user':'emma','port':123,'host':'192.168.1.123','password':'emma','database':'dbname'}conn=psycopg2.connect(**PG_CONF_123)#打开一个操作整个数据库的光标连接对象可以创建光标用来执行SQL语句cur=conn.cur

系统 2019-09-27 17:52:21 2078

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 2078

Python

Python字符串大小写转换拼接删除空白

1.字符串大小写转换string.title()#将字符串中所有单词的首字母以大写形式显示string.upper()#将字符串中所有字母转化为大写字母string.lower()#将字符串中所有字母转化为小写字母str="helloworld!"print(str.title())HelloWorld!print(str.upper())HELLOWORLD!print(str.lower())helloworld!2.字符拼接python中只用使用'+

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

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 2078

Python

Python—Web服务器(Apache)

Apache配置文件:httpd.conf文件#指定Apache的安装路径,此选项参数值在安装Apache时系统会自动把Apache的路径写入。ServerRoot"/www/server/apache"#Listen主要侦听web服务端口状态,默认为:80,即侦听所有的地址的80端口,注意这里也可以写成IP地址的侦听形式,不写即默认的地址:0.0.0.0Listen106.15.88.162:80Listen80#指定Apache运行用户配置Userww

系统 2019-09-27 17:49:45 2078

Python

python PIL和CV对 图片的读取,显示,裁剪,保存实现方法

PIL图片操作读取图片img=Image.open(“a.jpg”)显示图片im.show()#im是Image对象,im是numpy类型,通过Image.fromarray(nparr,mode='RGB')函数转换为Image对象图片的size(width,height)=img.size图片的模式mode=img.mode截区域img_c=img.crop(x1,y1,x2,y2)裁剪图片img=img.resize((size,size),Imag

系统 2019-09-27 17:48:58 2078

Python

Python thread demo

frommultiprocessingimportProcess,Queuefromtimeimporttimedeftask_handler(current_list,result_queue):total=0fornincurrent_list:total+=nresult_queue.put(total)defmain():processes=[]number_list=[xforxinrange(1,10000001)]result_queue=Q

系统 2019-09-27 17:48:29 2078

Python

python开头的coding设置方法

缘起:[root@CentOS7code]#pythonmulti_thread_mfw.pyFile"multi_thread_mfw.py",line138SyntaxError:Non-ASCIIcharacter'\xe5'infilemulti_thread_mfw.pyonline138,butnoencodingdeclared;seehttp://www.python.org/peps/pep-0263.htmlfordetails写完py

系统 2019-09-27 17:48:24 2078

Python

Python带你朗读网页

阅读更多万能的Python大法可以做很多有趣的事情,那我们今天来看看使用简单的Python来实现对一个网页的朗读吧!首先我们需要装一些必要的库:readability它是用来提取网页内的内容的pipinstallreadability-lxmlgoose它是一个文章提取器,我们用它来进行文章的提取pipinstallgoose3baidu-aip百度提供的PythonSDK,接口文档:http://ai.baidu.com/docs#/TTS-Online

系统 2019-09-27 17:48:22 2078

Python

python excel转换csv代码实例

为了提高工作效率(偷懒),用python去解决。工作需要,需要将excel文件转化为csv文件,要是手工的一个个去转换,每个sheet页不但有几十个字段,中间还夹杂着空格,然后按顺序转换成csv文件,这要是手工完成,一两个还行,多了那就是要死人的节奏了,这时候想到了python,走起。__author__='zxl'importpandasaspdimportosimportxlrdpath=r'/Users/zhangxl/Desktop/'filena

系统 2019-09-27 17:47:56 2078