python 之 subprocesss 模块、configparser 模块
6.18 subprocesss 模块
常用dos命令:
cd : changedirectory 切换目录
tasklist:查看任务列表
tasklist | findstr python :查看任务列表并筛选出python任务的信息
# python.exe 12360 Console 1 11,024 K
/?:查看命令使用方法
taskkill :利用PID结束任务
# D:\code>taskkill /F /PID 12360
linux系统(了解):
ps aux | grep python
kill -9 PID #-9表示强制结束任务
import subprocess
obj=subprocess.Popen('dir',
shell=True,
stdout=subprocess.PIPE, #正确管道
stderr=subprocess.PIPE #错误管道
)
print(obj) #<subprocess.Popen object at 0x000001F06771A3C8>
res1=obj.stdout.read() #读取正确管道内容
print('正确结果1: ',res1.decode('gbk'))
res2=obj.stdout.read()
print('正确结果2: ',res2.decode('gbk')) #只能取一次,取走了就空了
res3=obj.stderr.read() #读取错误管道内容
print('错误结果:',res3.decode('gbk'))
6.19 configparser 模块
my.ini文件:
[egon]
age=18
pwd=123
sex=male
salary=5.1
is_beatifull=True
[lsb]
age=30
pwd=123456
sex=female
salary=4.111
is_beatifull=Falase
import configparser
config=configparser.ConfigParser()
config.read('my.ini')
secs=config.sections()
print(secs) #['egon', 'lsb']
print(config.options('egon')) #['age', 'pwd', 'sex', 'salary', 'is_beatifull']
age=config.get('egon','age') #18 <class 'str'>
age=config.getint('egon','age') #18 <class 'int'>
print(age,type(age))
salary=config.getfloat('egon','salary')
print(salary,type(salary)) #5.1 <class 'float'>
b=config.getboolean('egon','is_beatifull')
print(b,type(b)) #True <class 'bool'>
python 之 subprocesss 模块、configparser 模块的更多相关文章
- 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 ...
- 小白的Python之路 day5 configparser模块的特点和用法
configparser模块的特点和用法 一.概述 主要用于生成和修改常见配置文件,当前模块的名称在 python 3.x 版本中变更为 configparser.在python2.x版本中为Conf ...
- hashlib模块configparser模块logging模块
hashlib模块 算法介绍 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢?摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长 ...
- os模块,os.path模块,subprocess模块,configparser模块,shutil模块
1.os模块 os表示操作系统该模块主要用来处理与操作系统相关的操作最常用的文件操作打开 读入 写入 删除 复制 重命名 os.getcwd() 获取当前执行文件所在的文件夹路径os.chdir(&q ...
- Python3 logging模块&ConfigParser模块
''' 博客园 Infi_chu ''' ''' logging模块 该模块是关于日志相关操作的模块 ''' import logging # logging.debug('debug') # log ...
- 常用模块(collections模块,时间模块,random模块,os模块,sys模块,序列化模块,re模块,hashlib模块,configparser模块,logging模块)
认识模块 什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编写的 ...
- Python全站之路----常用模块----configparser模块
config:配置 parser:解析 此模块用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser,在 python 2.x 里名字为 Co ...
- Python标准库之ConfigParser模块
配置文件的格式 a) 配置文件中包含一个或多个 section, 每个 section 有自己的 option: b) section 用 [sect_name] 表示,每个option是一个键值对, ...
- python标准库:Configparser模块
配置文件test.conf [section1] name = tank age = 28 [section2] ip = 192.168.1.1 port = 8080 示例 # -* - codi ...
- Python之xml文档及配置文件处理(ElementTree模块、ConfigParser模块)
本节内容 前言 XML处理模块 ConfigParser/configparser模块 总结 一.前言 我们在<中我们描述了Python数据持久化的大体概念和基本处理方式,通过这些知识点我们已经 ...
随机推荐
- Parse发布Bolts,一个面向iOS和Android的底层库集合
转载自:http://www.infoq.com/cn/news/2014/02/parse-announces-bolts 数月前,Parse被Facebook收购.最近,它开源了一个面向iOS和A ...
- [转] 修改sqlserver的数据库名、物理名称和逻辑文件名
转载: https://blog.csdn.net/dym0080/article/details/81017777
- 2019年领航杯 江苏省网络信息安全竞赛 初赛部分writeup
赛题已上传,下载连接:https://github.com/raddyfiy/2019linghangcup 做出了全部的misc和前三道逆向题,排名第10,暂且贴一下writeup. 关卡一 编码解 ...
- Tomcat启动过程中找不到JAVA_HOME JRE_HOME的解决方法
转自:http://blog.sina.com.cn/s/blog_61c006ea0100l1u6.html 原文: 在XP上明明已经安装了JDK1.5并设置好了JAVA_HOME,可偏偏Tomca ...
- ubuntu进程监视器htop 清除黄色内存(缓存)
大意是:对于CPU显示条: 蓝色为:低优先级的线程 绿色为:正常优先级线程 红色为:内核线程 对于内存显示条: 蓝色为:缓冲区(buffers) 绿色为:已使用的内存 (橘)黄色为:高速缓存(cach ...
- locust性能测试脚本模板
locust性能测试脚本模板 #!/usr/bin/env python # -*- coding: utf-8 -*- import time from locust import HttpLocu ...
- Spring 接口日志 AOP
接口日志记录AOP实现-LogAspect - 91博客it技术开发者 - 博客园https://www.cnblogs.com/007sx/p/5810818.html Spring AOP(一) ...
- Mac 终端显示git分支
1 进入你的home目录 cd ~ 2 编辑.bashrc文件 vi .bashrc 3 将下面的代码加入到文件的最后处 function git_branch { branch="`git ...
- Dart自定义库、系统库和第三方库
/* 前面介绍Dart基础知识的时候基本上都是在一个文件里面编写Dart代码的,但实际开发中不可能这么写,模块化很重要,所以这就需要使用到库的概念. 在Dart中,库的使用时通过import关键字引入 ...
- python的url正则表达式
网上有很多的正则表达式版本,大部分都不好使,下面这个比较好用: http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F] ...