Python
无用之人死
数据分析
展开
-
Python——*args的用法
# coding=utf-8# *args主要用于函数定义,预先不知道会传递多少个参数,*args传递一个参数数量可变的元组类型给函数def test_var_args(f_arg, *args): print("第一个参数为", f_arg) print(args) print(type(args)) for arg in args: print(转载 2016-08-03 19:49:28 · 3089 阅读 · 0 评论 -
Python——requests库
# coding=utf-8import requests# 1 基本请求r1 = requests.post('http://httpbin.org/post')r2 = requests.get('http://httpbin.org/put')r3 = requests.delete('http://httpbin.org/delete')r4 = requests.head('h转载 2016-08-03 20:17:44 · 361 阅读 · 0 评论 -
Python——urllib库
一urllib库的基本使用1读取静态网页读取动态网页动态传送参数数据1 post方式2 get方式二urllib库的高级使用设置Headers代理设置超时设置一、urllib库的基本使用1读取静态网页import urllibimport urllib2url = 'http://cuiqingcai.com/947.html'print urllib2.urlopen(ur转载 2016-08-03 20:16:51 · 418 阅读 · 0 评论 -
Python——urllib库的高级使用
# coding=utf-8import urllibimport urllib2import reimport StringIOimport gzip# 1 提取动态的lt和executionurl = 'https://passport.csdn.net/account/login?from=http://my.csdn.net/my/mycsdn'string = urllib转载 2016-08-03 20:15:14 · 303 阅读 · 0 评论 -
Python——装饰器
# coding=utf-8def a_new_decorator(a_func): def wrapthefunction(): print("I'm doing some boring work before executing a_func()") a_func() print("I'm doing some boring work afte转载 2016-08-03 19:46:03 · 385 阅读 · 0 评论 -
Python——itertools
import itertoolsnaturals = itertools.count(10) # 自然数序列,从10开始print(type(naturals))# for n in naturals:# print(n)cd = itertools.cycle('ABCDEFGHIJKLMNOPQRSTUVWXYZ') # 无限循环# for c in cd:# pr转载 2016-08-03 19:47:32 · 247 阅读 · 0 评论 -
Python——urllib库的基本使用
# coding=utf-8# Urllib库的基本使用import urllibimport urllib2# 1 读取网页内容:先使用urllib2.urlopen打开网址,再read读取html = 'http://cuiqingcai.com/947.html'response = urllib2.urlopen(html, )# print response.read()"转载 2016-08-03 20:01:36 · 298 阅读 · 0 评论 -
Python——pdb调试
# coding=utf-8import pdb"""1.从命令行使用python debugger调试脚本python -m pdb my_script.py2.从脚本内部设置断点import pdb: pdb.set_trace() c:继续执行 w:显示正在执行的代码的上下文信息 a:打印当前函数的参数列表 s:执行当前代码行,并停留在第一个能转载 2016-08-03 19:55:09 · 262 阅读 · 0 评论 -
Python——生成器
# coding=utf-8import time"""生成器(Generators):要理解生成器,得知道以下几个概念: 1.可迭代对象iterable: python中任意的对象,只要他定义了可以返回一个迭代器的__iter__方法, 或者定义了可以支持下标索引的__getitem__方法,那它就是一个可迭代对象. 简单地说,可迭代对象转载 2016-08-03 19:52:56 · 273 阅读 · 0 评论 -
Python——更新所有包
# coding=utf-8import pipfrom subprocess import callfor dist in pip.get_installed_distributions(): call("pip install --upgrade " + dist.project_name, shell=True)转载 2016-08-03 19:51:35 · 2780 阅读 · 0 评论 -
Python——**kwargs
# coding=utf-8# **kwargs允许不定长度的键值对作为参数传给函数# greet 问候def greet_me(**kwargs): for key, value in kwargs.items(): print(key, value) print(type(kwargs))greet_me(name1="Michael Jack", name2转载 2016-08-03 19:50:29 · 272 阅读 · 0 评论 -
Python——BeautifulSoup
# coding=utf-8from bs4 import BeautifulSoupimport bs4import rehtml = """<html><head><title>THe Dormouse's story</title></head><body><p class="title" name="dromouse"><b> The Dormouse's story</b></转载 2016-08-03 20:20:09 · 408 阅读 · 0 评论