re模块    
内部实现不是Python 而是调用了c的库 re是什么
  正则 表达 式子
  就是一些带有特殊含义的符号或者符号的组合
作用: 对字符串进行过滤
  在一对字符串中找到所关心的内容
  你就需要告诉计算机过滤规则是什么样
  通过什么方式来告诉计算机 就通过正则表达式
re模块常用方法
findall -------- 从左往右查找所有满足条件的字符 返回一个列表
search -------- 返回第一个匹配的字符串 结果封装为对象 span=(0,5)匹配的位置 match匹配的值
match --------- 匹配行首 返回值与search相同
----------------- 对于search match 匹配的结果通过group来获取
compile -------- 将正则表达式封装为一个正则对象 好处是可以重复使用这个表达式
第一步:
学习正则表达式 各种符号所表示的含义
各种符号
常用的
\w \s \d . ^ $
范围匹配
[] a|b
重复匹配
{} + * ?
分组
()
常用的方法:
findall
search
match
sub
split 2.subprocess
run 返回执行结果对象
call 返回执行状态码
Popen 返回的也是对象 out in err 进程间的数据访问
import re
#待处理字符串
# src = 'hades'
#在字符串中查找所有满足条件的
# print(re.findall('ad',src)) # \w 字母数字下划线
# \W 非字母数字下划线 与\w相反
# print(re.findall('\w',src))
# print(re.findall('\W',src)) # \s 所有不可见字符
# \S 所有可见字符
# print(re.findall('\s',src))
# print(re.findall('\S',src)) # \d 所有数字可见
# \D 所有非数字可见
# print(re.findall('\d',src))
# print(re.findall('\D',src)) # 特殊字符直接匹配
# print(re.findall('\n',src))
# print(re.findall('\t',src)) # . 除了\n以外任意字符
# print(re.findall('.',src)) # \s \w \d . 都是匹配单个字符
#匹配重复字符 * + ? {} # * 前面的表达式出现任意次
# print(re.findall('\d*','1 12 aa')) # + 重复1次或多次
# print(re.findall('\d+','1 1221abc41515a aa')) # ? 重复0次或1次
# print(re.findall('\d?','aa bb a1c 1C1 哈哈哈 123')) # {n,m} 最少n次 最多m次
# print(re.findall('\d{1,3}','1 12 123 1234 123456')) # {n} 必须是n次
# print(re.findall('[a-z]{3}','a aa aaa aaaa aaaaa')) # {,m} 最大m次 0-m
# print(re.findall('[a-z]{,3}','a aa aaa aaaa aaaaa')) #匹配范围
# | 0|1|2 或
# print(re.findall('0|1|2','12413sdfg')) # [] 字符集合 括号内的符号不是整体
# print(re.findall('[012]','1982asasa')) # 在范围匹配时使用 ^ 托字符表示取反
# print(re.findall('[^0-9]','1982asasa')) #找出范围内 数字0-9 字母a-z A-Z 注意(减号只有在两个字符中间才代表范围,在两边都是普通字符)
# print(re.findall('[0-9a-zA-Z]','1982+asasa')) # ^ 匹配行首
# print(re.findall('^h','helhhlohh')) # $ 匹配行尾 注意:写在表达式后面
# print(re.findall('s$','helhhlohs')) # 单词边界
# print(re.findall('o\\b','hello word hi hades')) #双斜杠?
# print(re.findall('a\\\\c','aakakja\c')) #贪婪匹配 * + 注意: 不是固定写法 是一种现象
#会一直匹配到不满足条件为止 用问号来阻止贪婪匹配(匹配最少满足条件的字符数)
# print(re.findall('\w+? ','dfgregersg'))
# print(re.findall('\w*? ','dfgregersg')) # () 用于给正则表达式分组(group)
#什么时候需要阻止贪婪
# src = '<img src="www.baidupic.shuaiqi.jpg"><img src="www.baidupic.shuaiqi.jpg"><img src="www.baidupic.shuaiqi.jpg">'
#请用正则表达式取图片地址
# print(re.findall('src="(.+?)"',src))
# 了解 加上?: 可以取消括号中的优先级
# print(re.findall('src="(?:.+?)"',src))

subprocess模块
sub 子
process 进程
什么是进程
正在进行中的程序 每当打开一个程序就会开启一个进程
每个进程包含运行程序所需的所有资源
正常情况下,不可以跨进程访问数据
但是有些情况下就是需要访问别的进程数据 提供一个叫做管道的对象 专门用于跨进程通讯 作用: 用于执行系统命令 常用方法:
run 返回一个表示执行结果的对象
call 返回的执行的状态码
总结: subprocess的好处是可以获取指令的执行结果
subprocess执行指令时,可以在子进程中这样

Python re模块 subprocess模块的更多相关文章

  1. python笔记之subprocess模块

    python笔记之subprocess模块 [TOC] 从Python 2.4开始,Python引入subprocess模块来管理子进程,以取代一些旧模块的方法:如 os.system.os.spaw ...

  2. Python全栈之路----常用模块----subprocess模块

    我们经常需要通过Python去执行一条系统命令或脚本,系统的shell命令是独立于你的python进程之外的,每执行一条命令,就是发起一个新进程,通过python调用系统命令或脚本的模块在python ...

  3. Python中的subprocess模块

    Subprocess干嘛用的? subprocess模块是python从2.4版本开始引入的模块.主要用来取代 一些旧的模块方法,如os.system.os.spawn*.os.popen*.comm ...

  4. python学习之-- subprocess模块

    subprocess 模块 功能:用来生成子进程,并可以通过管道连接它们的输入/输出/错误,以及获得它们的返回值.它用来代替多个旧模块和函数: os.system os.spawn* os.popen ...

  5. python实现系统调用cmd命令的模块---subprocess模块

    如果要python实现系统命令或者调用脚本,python中可以利用os或者subprocess模块实现: 一.os模块: # coding:utf-8 command = os.system('net ...

  6. python day 9: xlm模块,configparser模块,shutil模块,subprocess模块,logging模块,迭代器与生成器,反射

    目录 python day 9 1. xml模块 1.1 初识xml 1.2 遍历xml文档的指定节点 1.3 通过python手工创建xml文档 1.4 创建节点的两种方式 1.5 总结 2. co ...

  7. Python基础之模块:6、hashlib模块 subprocess模块 logging模块

    目录 一.hashlib模块 1.简介 2.基本操作与用法 二.subprocess模块 1.简介 2.基本操作与用法 三.logging模块 1.简介 2.基本操作与用法 一.hashlib模块 1 ...

  8. python hashlib模块 logging模块 subprocess模块

    一 hashlib模块 import hashlib md5=hashlib.md5() #可以传参,加盐处理 print(md5) md5.update(b'alex') #update参数必须是b ...

  9. Python中使用subprocess模块远程执行命令

    使用subprocess模块执行远程命令 服务端代码 1 import socket 2 import subprocess 3 4 sh_server = socket.socket() 5 sh_ ...

随机推荐

  1. JS计算字符串实际长度

    http://www.qttc.net/201207136.html // UTF8字符集实际长度计算 function getStrLeng(str){ var realLength = 0; va ...

  2. 创建Mesh->格子地图转NavMesh->可破坏墙壁

    1. 前言     最近连续做了很多代码动态生成Mesh的工作,从动态生成修改瞄准范围的Mesh到可破坏的墙壁,以及之前写了一半导航网格生成.     想借此机会整理下最近的积累,如果在阅读过程中发现 ...

  3. bzoj 3143 [Hnoi2013]游走【高斯消元+dp】

    参考:http://blog.csdn.net/vmurder/article/details/44542575 和2337有点像 设点u的经过期望(还是概率啊我也分不清,以下都分不清)为\( x[u ...

  4. A - Supercentral Point CodeForces - 165A

    One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of point ...

  5. docker数据存储

    docker数据存储 docker提供了三种类型的数据存储 第一种:将数据直接存储在容器中 第二种:将数据映射到外部的本机目录 第三种:将数据映射到专门的数据卷容器

  6. Android Dialogs(4)Dialog事件处理

    Passing Events Back to the Dialog's Host When the user touches one of the dialog's action buttons or ...

  7. Statistics gathering and SQL Tuning Advisor

    1. https://www.pythian.com/blog/statistics-gathering-and-sql-tuning-advisor/ Our monitoring software ...

  8. ie浏览器和火狐浏览器对对容器宽度定义的差异

    首先我们说说firefox和IE对CSS的宽度显示有什么不同: 其实CSS ’width’ 指的是标准CSS中所指的width的宽度,在firefox中的宽度就是这个宽度.它只包含容器中内容的宽度.而 ...

  9. javax.xml.bind.UnmarshalException: 意外的元素 (uri:"", local:"xml")。所需元素为(none)

    将xml转换为object时候报错:javax.xml.bind.UnmarshalException: 意外的元素 (uri:"", local:"xml") ...

  10. Node.js——基本服务开启

    标注模式 var http = require('http'); var server = http.createServer(); server.on('request', function (re ...