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 2144
1.os.popen运行shell列表命令复制代码代码如下:deftraverseDirByShell(path):forfinos.popen('ls'+path):printf.strip()2.利用glob模块glob.glob(path)返回带目录的文件名.通配符和shell相似.path不能包含shell变量.复制代码代码如下:deftraverseDirByGlob(path):path=os.path.expanduser(path)forf
系统 2019-09-27 17:49:59 2144
这是我在CSDN的第一篇博客,假期刚自学Python,尝试爬取了一下豆瓣top250.希望可以有大佬指点感谢importrequestsfrombs4importBeautifulSoupdefgethtml(url):try:kv={'user-agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/59.0.3071.115Safari/
系统 2019-09-27 17:49:53 2144
python中with可以明显改进代码友好度,比如:复制代码代码如下:withopen('a.txt')asf:printf.readlines()为了我们自己的类也可以使用with,只要给这个类增加两个函数__enter__,__exit__即可:复制代码代码如下:>>>classA:def__enter__(self):print'inenter'def__exit__(self,e_t,e_v,t_b):print'inexit'>>>withA()
系统 2019-09-27 17:49:50 2144
1.python中创建进程的两种方式:frommultiprocessingimportProcessimporttimedeftest_():print'-----test-----'if__name__=='__main__':p=Process(target=test_)p.start()whileTrue:print'--main--''''1.通过process类创建一个进程对象,然后start即可开启进程,testtest_函数是进程实现的功能
系统 2019-09-27 17:49:44 2144
前言大部分初学编程的人来说刚开始都会练习判断两个数或者三个数的大小,来熟悉某种语言的特性和最基本的if,else循环,当我们学习了更高级的语法知识后,又会有不同的实现方式,比如这道练习题依次接收用户输入的3个数,排序后打印现在我们来看一下在Python中都有哪些方法来实现:1,采用分支结构,用最基本的if和else来实现:a=int(input('a>>>'))b=int(input('b>>>'))c=int(input('c>>>'))ifa>b:if
系统 2019-09-27 17:49:18 2144
python:如何将excel文件转化成CSV格式importpandasaspddata=pd.read_excel('123.xls','Sheet1',index_col=0)data.to_csv('data.csv',encoding='utf-8')将Excel文件转为csv文件的python脚本#!/usr/bin/envpython__author__="lrtao2010"'''Excel文件转csv文件脚本需要将该脚本直接放到要转换的E
系统 2019-09-27 17:48:54 2144
前言R:代表redis-cliP:代表python的redis准备pipinstallredispool=redis.ConnectionPool(host='39.107.86.223',port=6379,db=1)redis=redis.Redis(connection_pool=pool)redis.所有命令下面命令所有命令我都省略了,有和Python内置函数冲突的我会加上redis.全局命令dbsize(返回key的数量)R:dbsizeP:pr
系统 2019-09-27 17:48:51 2144
withopen("1.txt")asf:whileTrue:line=f.readline()ifnotline:break;print(line.rstrip())
系统 2019-09-27 17:48:48 2144
缘起:[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 2144