一、OS模块

  1、os.system('ls -l') #子shell运行,获取返回值,不是结果。

  2、os.popen('ls -l').read() #获取结果。

 

二、sys模块

  1、sys.argv

  2、sys.exit

  3、sys.path

三、shutil模块

  1、压缩归档

import shutil
ret = shutil.make_archive("/archive", 'gztar', root_dir='/var/log/www/access.log')

  2、zipfile

import zipfile

# 压缩
z = zipfile.ZipFile('laxi.zip', 'w')
z.write('a.log')
z.write('data.data')
z.close() # 解压
z = zipfile.ZipFile('laxi.zip', 'r')
z.extractall()
z.close()

  3、tarfile

  

import tarfile

# 压缩
tar = tarfile.open('your.tar','w')
tar.add('/Users/wupeiqi/PycharmProjects/bbs2.zip', arcname='bbs2.zip')
tar.add('/Users/wupeiqi/PycharmProjects/cmdb.zip', arcname='cmdb.zip')
tar.close() # 解压
tar = tarfile.open('your.tar','r')
tar.extractall() # 可设置解压地址
tar.close()

  4、shelve

import shelve
def CreateData():
db=shelve.open('db.dat','c')
db['int']=1
db['float']=2.3
db['string']='i like python.'
db['key']='value'
db.close() def LoadData():
db=shelve.open('db.dat','r')
for item in db.items():
print(item)
db.close()
if __name__=="__main__":
CreateData()
LoadData()

  

四、subprocess

import subprocess
1、call,run
subprocess.call('df -h',shell=True)
ret=subprocess.Popen('df -h',shell=True,stdout=subprocess.PIPE)
print(ret.stdout.read() 2、交互
obj = subprocess.Popen(["python"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
obj.stdin.write('print 1 \n ')
obj.stdin.write('print 2 \n ')
obj.stdin.write('print 3 \n ')
obj.stdin.write('print 4 \n ') out_error_list = obj.communicate()
print out_error_list

  

python3-day6(模块)的更多相关文章

  1. [转]python3之模块psutil系统性能信息

    转自:https://www.cnblogs.com/zhangxinqi/p/9106265.html 阅读目录 1.psutil模块安装 2.获取CPU信息 3.内存信息 4.磁盘信息 5.网络信 ...

  2. 【转】Python3 configparse模块(配置)

    [转]Python3 configparse模块(配置) ConfigParser模块在python中是用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(s ...

  3. Python3 operator模块关联代替Python2 cmp() 函数

    Python2 cmp() 函数 描述 cmp(x,y) 函数用于比较2个对象,如果 x < y 返回 -1, 如果 x == y 返回 0, 如果 x > y 返回 1. Python ...

  4. Python3 logging 模块

    Python3 logging模块 日志模块: 用于便捷记录日志且线程安全的模块 CRITICAL = 50 FATAL = CRITICAL ERROR = 40 WARNING = 30 WARN ...

  5. python3 selenium模块Chrome设置代理ip的实现

    python3 selenium模块Chrome设置代理ip的实现 selenium模块Chrome设置代理ip的实现代码: from selenium import webdriver chrome ...

  6. python3 导入模块

    python3导入模块和python2  有些不同   需要指定相对目录 如,在Project下有一个nlp目录里面有一个ltp模块,则 from n1.ltp import Clawer

  7. python3之模块

    1.python3模块 模块是一个包含所有你定义的函数和变量的文件,其后缀名是.py.模块可以被别的程序引入,以使用该模块中的函数等功能.这也是使用 python 标准库的方法. 模块让你能够有逻辑地 ...

  8. Python3数据库模块(sqlite3,SQLite3)

    一.sqlite命令 创建数据库:在控制台sqlite3 name .databases     查看数据库 .tables            查看表格名 databaseName .dump & ...

  9. python3 re模块

    一.常用正则表达式符号和语法: '.' 匹配所有字符串,除\n以外 ‘-’ 表示范围[0-9] '*' 匹配前面的子表达式零次或多次.要匹配 * 字符,请使用 \*. '+' 匹配前面的子表达式一次或 ...

  10. python3 os模块

    os模块就是对操作系统进行操作,这个模块提供了一种使用操作系统相关功能的可移植方式.1.系统信息 posix.uname_result(sysname='Linux', nodename='liang ...

随机推荐

  1. 【实验 1-2】编写一个简单的 UDP 服务器和 UDPP 客户端程序。程序均为控制台程序窗口。

    1.服务器 #include<winsock2.h> //包含头文件#include<stdio.h>#include<windows.h>#pragma comm ...

  2. hdu2795Billboard(线段树)

    http://acm.hdu.edu.cn/showproblem.php?pid=2795 单点更新,树存储的为某一行内剩余的长度 // File Name: hdu2795.cpp // Auth ...

  3. 高速排序-c++(分别用数组和容器实现)

    /********************************************************************** *版权全部 (C)2014, cheng yang. * ...

  4. [置顶] Linux协议栈代码阅读笔记(一)

    Linux协议栈代码阅读笔记(一) (基于linux-2.6.21.7) (一)用户态通过诸如下面的C库函数访问协议栈服务 int socket(int domain, int type, int p ...

  5. coco2d-html5制作弹弓射鸟第一部分---橡皮筋

    一.写在前面的话 最近在学习cocos2d-html5方面的知识,一直想从事游戏方面的工作,自己也找了好多资料.网上关于cocos2d-html5的教程真的不多,也只有自己摸索,慢慢看示例代码.由于本 ...

  6. (转)弹出窗口lhgDialog API文档

    应用到你的项目 如果您使用独立版本的lhgDialog窗口组件,您只需在页面head中引入lhgcore.lhgdialog.min.js文件,4.1.1+版本做了修改可以和jQuerya库同时引用, ...

  7. The type or namespace name 'Script' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

    应该说是 .net4 的bug,没有所谓的 System.Web.Extensions.dll 库文件,需要将项目的 Target Framework修改为 3.5版本,才能加载System.Web. ...

  8. string的一些操作,类似数组

    1.串的切割 var a="hello world";//a.length=11 alert(a.slice(3)); alert(a.substring(3)); alert(a ...

  9. poj3685 二分套二分

    F - 二分二分 Crawling in process... Crawling failed Time Limit:6000MS     Memory Limit:65536KB     64bit ...

  10. uva 296 - Safebreaker

    枚举法 #include <cstdio> using namespace std; int main() { int t, n, i, j, k; scanf("%d" ...