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数据持久化的大体概念和基本处理方式,通过这些知识点我们已经 ...
随机推荐
- 2018-2019 20165226 Exp9 Web安全基础
2018-2019 20165226 Exp9 Web安全基础 目录 一.实验内容说明及基础问题回答 二.实验过程 Webgoat准备 XSS攻击 ① Phishing with XSS 跨站脚本钓鱼 ...
- Simplifying Failures
# # Finish the delta debug function ddmin # import re def test(s): print s, len(s),repr(s) if re.sea ...
- unity疯狂牧场完整项目源码 - Frenzy Farming time management game kit V1.0
You will love this game kit! Have you ever wondered what it would be like to run your own farm? Look ...
- Activity: launchMode 和 Intent.FLAG_ACTIVITY_CLEAR_TOP
Activity 的 launchMode: 1. standard: 标准模式 这种启动模式为标准模式,也是默认模式.每当我们启动一个Activity,系统就会相应的创建一个实例,不管这个实例是否已 ...
- vim 显示行号 临时&永久
设置vim 永久显示行号 - electrocrazy的博客 - CSDN博客https://blog.csdn.net/electrocrazy/article/details/79035216 v ...
- NonSerialized 属性忽略序列化报错'NonSerialized' is not valid on this declaration type
[XmlIgnore] [NonSerialized] public List<string> paramFiles { get; set; } //I get the following ...
- (转)设置了RemoveIPC=yes 的RHEL7.2 会crash掉Oracle asm 实例和Oracle database实例
设置了RemoveIPC=yes 的RHEL7.2 会crash掉Oracle asm 实例和Oracle database实例,该问题也会在使用Shared Memory Segment (SHM ...
- c#反射动态创建窗体
根据窗体的名称动态创建窗体 Assembly assembly = Assembly.GetExecutingAssembly(); // 实例化窗体 try { Form f ...
- flutter Card卡片列表组件
一个 Material Design 卡片.拥有一个圆角和阴影 import 'package:flutter/material.dart'; import './model/post.dart'; ...
- ISO/IEC 9899:2011 条款6.8.2——标签语句
6.8.2 复合语句 语法 1.compound-statement: { block-item-listopt } block-item-list: block-item block-i ...