python--configparser模块,subprocess模块
来源:互联网 发布:软件演示平台 编辑:程序博客网 时间:2024/06/06 01:59
configparser模块
configparser文件格式
[DEFAULT]ServerAliveInterval = 45Compression = yesCompressionLevel = 9ForwardX11 = yes [bitbucket.org]User = hg [topsecret.server.com]Port = 50022ForwardX11 = no
写一个configparser文件 import configparserconfig=configparser.ConfigParser()#制作一个ConfigParser object#"DEFAULT"是固定用词,该key下为共有信息config["DEFAULT"]={'ServerAliveInterval': '45',}
#可以任意取名config['bitbucket.org'] = {'User':'hg'}config['topsecret.server.com'] = {'Host Port':'50022','ForwardX11':'no'}with open('ss.ini','w') as f: config.write(f)#固定格式
import configparserconfig=configparser.ConfigParser()config.read('a.cfg')#查看所有的标题res=config.sections() #['section1', 'section2']print(res)#查看标题section1下所有key=value的keyoptions=config.options('section1')print(options) #['k1', 'k2', 'user', 'age', 'is_admin', 'salary']#查看标题section1下所有key=value的(key,value)格式item_list=config.items('section1')print(item_list) #[('k1', 'v1'), ('k2', 'v2'), ('user', 'egon'), ('age', '18'), ('is_admin', 'true'), ('salary', '31')]#查看标题section1下user的值=>字符串格式val=config.get('section1','user')print(val) #egon#查看标题section1下age的值=>整数格式val1=config.getint('section1','age')print(val1) #18#查看标题section1下is_admin的值=>布尔值格式val2=config.getboolean('section1','is_admin')print(val2) #True#查看标题section1下salary的值=>浮点型格式val3=config.getfloat('section1','salary')print(val3) #31.0
http://www.cnblogs.com/linhaifeng/articles/6384466.html#_label9
==================================================================================================
subprocess模块
import subprocess# print(subprocess.Popen('dir',shell=True))#在python 中使用window命令#开启新的进程# s=subprocess.Popen('dir',shell=True,stdout=subprocess.PIPE)#子进程将执行结果放到管道中# print(s.stdout.read().decode('gbk'))#父进程从管道中取出数据并打印
阅读全文
0 0
- python--configparser模块,subprocess模块
- Python subprocess、configparser、yaml模块
- python ConfigParser、shutil、subprocess、ElementTree模块简解,configparser
- PYTHON 配置文件模块 ConfigParser
- Python模块之: ConfigParser
- python 之ConfigParser模块
- Python ConfigParser模块
- Python Configparser模块
- python ConfigParser 模块学习
- python 的 ConfigParser 模块
- Python-ConfigParser模块简介
- python模块之ConfigParser
- Python ConfigParser模块教程
- python-ConfigParser模块学习
- python ConfigParser模块
- python ConfigParser模块详解
- python 模块configparser
- Python模块之ConfigParser
- PowerBuilder9.0中Datawindow另存为pdf文件
- Linux基础常用命令
- 腾讯云IM中经常使用的路径
- py 一些built-in函数
- 文章标题
- python--configparser模块,subprocess模块
- Java synchronized详解
- C语言快速讲解(五)结构体与指针
- HanLPTokenizer HanLP分词器
- mysql in 多张表
- SSM框架CRUD代码生成器
- IIS 内部运行机制
- 第一次ACM选拔赛
- LeetCode-409. Longest Palindrome (Java)