一:什么是魔法函数看一个简单的例子:classCompany:def__init__(self,employee__list):self.employee=employee__listcompany=Company(['tom','jack','jane'])employee=company.employeeforiteminemployee:print(item)打印结果无疑是tom,jack,jane。那么换一种方式,使用Python的魔法函数:cla
系统 2019-09-27 17:52:26 2089
本文实例讲述了Python基于BeautifulSoup和requests实现的爬虫功能。分享给大家供大家参考,具体如下:爬取的目标网页:http://www.qianlima.com/zb/area_305/这是一个招投标网站,我们使用python脚本爬取红框中的信息,包括链接网址、链接名称、时间等三项内容。使用到的Python库:BeautifulSoup、requests代码如下:#-*-coding:utf-8-*-importrequestsfr
系统 2019-09-27 17:52:10 2089
基本常识python中的左位移和右位移利用Python在一个文件的头部插入数据withopen(path,"r+")asf:old=f.read()f.seek(0)f.write(data)f.write(old)Debugxpath中遇到[]AttributeError:‘dict’objecthasnoattribute‘iteritems’Python3.5中:iteritems变为items【Python】ufunc‘subtract’didno
系统 2019-09-27 17:52:10 2089
随机整数:复制代码代码如下:>>>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:25 2089
python环境搭建常用的python环境管理工具:pyenv&&virtualenvpyenv#安装到~/.pyenv当中,如果使用了zsh,那么将.bashrc-->.zshrcgitclonehttps://github.com/pyenv/pyenv.git~/.pyenvecho'exportPYENV_ROOT="$HOME/.pyenv"'>>~/.bashrcecho'exportPATH="$PYENV_ROOT/bin:$PATH"'>
系统 2019-09-27 17:49:57 2089
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 2089
作业一:需求:写函数,计算传入字符串中的【数字】、【字母】、【空格】以及【其他】的个数1#!/usr/bin/envpython2#-*-coding:utf-8-*-34#先定义一个函数5deffunc(args):6#定义一个计算数字的变量7digit_num=08#定义一个计算字母的变量9al_num=010#定义一个计算空格的变量11spance_num=012#定义一个计算其他的变量13other_num=01415foriinargs:16if
系统 2019-09-27 17:49:36 2089
一、往文件中写入数据往TXT文件写入的时候报错'gbk'codeccan'tencodecharacter'\xXX'inpositionXX打开文件时,增加一个选项:defwirteFile(content):path=os.getcwd()a_path=os.path.join(path,"content.txt")f=open(a_path,"w+",encoding="utf-8")f.write(content)f.close()open()中添
系统 2019-09-27 17:49:29 2089
【摘要】本节中,我们利用requests库和正则表达式来抓取猫眼电影TOP100的相关内容。requests比urllib使用更加方便,而且目前我们还没有系统学习HTML解析库,所以这里就选用正则表达式来作为解析工具。1.本节目标本节中,我们要提取出猫眼电影TOP100的电影名称、时间、评分、图片等信息,提取的站点URL为http://maoyan.com/board/4,提取的结果会以文件形式保存下来。2.准备工作在本节开始之前,请确保已经正确安装好了r
系统 2019-09-27 17:48:56 2089
本文实例讲述了python自定义装饰器。分享给大家供大家参考,具体如下:先看一个例子defdeco(func):print("beforemyfunc()called.")func()print("aftermyfunc()called.")returnfunc@decodefmyfunc():print("myfunc()called.")#myfunc=deco(myfunc)#与上面的@deco等价myfunc()print("***********
系统 2019-09-27 17:47:58 2089