split 数据分隔(巡检)
1 python 的 commands
在虚拟机Linux中执行shell命令
Python 2.X 后内置的模块,提供了执行命令的简易入口
python 在3.0之后 移除commands命令 取而代之 是 subprocess
Python之系统交互(subprocess)
2 字典遍历
3
4split 分隔
# 以 "-" 分隔
name = 'tony-jone-kiki-bob'
list = name.split("-",1)
print(list)
#['tony', 'jone-kiki-bob']
# 以冒号为分隔
maohao = 'number:1010100101010'
fen = maohao.split(":")[1]
print (fen) #1010100101010
#splitlines()分隔字符串
u = 'li \n ui \n ok \n ok'
p = u.splitlines()
print (p) #['li', 'ui', 'ok', 'ok']
o = 'li \r ay \r ffff \r ssss'
s = o.splitlines()
print (s) #['li', 'ay', 'ffff', 'ssss']
#splitlines()分隔字符串 的最后一行
mystr = 'hello\nworld\nand\nhello\npython'
print (mystr)
print(mystr.splitlines())[-1]
#python
#print(mystr.split('\n'))
#以空格分隔
big_hhh = 'big 0.2'
jiji = big_hhh.split()
print (jiji)
#['big', '0.2']
#添加元素
ssddd = 'BIG BIG'
ssddd_dd = 'hhhhhhhhhhh'.join(ssddd.split())
print (ssddd_dd)
#BIGhhhhhhhhhhhBIG
#取倒数第5个
ijiji = "11 22 3 4 55 66 777 8888 99999"
ososdf =ijiji.split()[-5:]
print (ososdf)
#['55','66', '777', '8888', '99999']
Python re提取正则表达式匹配的字符
1 输入第三方模块 import re
re.split
# 分隔空格
import re
ll = "a b c d"
print(re.split(r"[ ]+", ll))
#['a', 'b', 'c', 'd']
”|“分割
string = "liu|zhi|wei"
name1 = string.split("\\|")
print(name1)
string = "liu|zhi|wei"
name2 = string.split("|")
print(name2)
r = '''%555%%%55'''
print(r.split("%%%"))
#['%555', '55']

浙公网安备 33010602011771号