随笔分类 - Python
python 查找指定内容的txt文件
摘要:程序设计思路:1. 利用os.walk()找出所有的文件;2.利用正则找到指定后缀的文件;3.找到需要的txt文件后,通过open().readlines()读取文件中每行数据;4.读取后,保存正则匹配到数据的文件;5.你懂的。#!/usr/bin/env python#coding:utf8imp...
阅读全文
python 图片爬虫
摘要:#!/usr/bin/env python#coding:utf-8import urllibimport redef GetHtml(url): """获取HTML页面所有元素.""" page = urllib.urlopen(url) html = page.read() ...
阅读全文
switch 与 python字典
摘要:python 中并没有switch语句,但是有一个数据类型与switch语句特别相似,它就是 dict{ key: value, ...}下面用 dict{ key:value,..} 来简单的实现switch语句:#!/usr/bin/env python#coding:utf-8from __f...
阅读全文
python中函数接收多余参数
摘要:代码:def fun(x): return x print fun(10)函数fun(x)接受参数是x,传入数字"10",打印函数的返回值结果 就是10,如果我传递多个参数时,程序就会出错,如下图:def fun(x): return xprint(fun(10,20))Trace...
阅读全文
centos 更新python
摘要:1、CentOS安装Python的依赖包yum groupinstall "Development tools"yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-...
阅读全文
debuggee python
摘要:my_debugger_defines.py 1 #encoding:utf-8 2 3 from ctypes import * 4 from sys import version as py_ver 5 6 # In python 2.7.6, LPBYTE is not defined i...
阅读全文
递归函数 Python
摘要:函数:def fact(n): if n==1: return 1 return n * fact(n-1)递归过程:print(fact(5))>>fact(5)>>5 * fact (4)>>5 * (4 * fact(3))>>5 * (4 * (3 * fact(2)))>>5 *...
阅读全文
* 和 ** python
摘要:*代表tuple集合,**代表dictdef func(a, b, c=0, *args, **kw) print ('a=',a, 'b=',b,'c=',c,'args=',args,'kw=',kw)>> func(1,2,c=3)>>a=1 b=2 c=3 args=() kw={}>>f...
阅读全文
浙公网安备 33010602011771号