s12-20160130-day06

*:first-child {
margin-top: 0 !important;
}

body>*:last-child {
margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}

h1 {
font-size: 28px;
color: #000;
}

h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}

h3 {
font-size: 18px;
}

h4 {
font-size: 16px;
}

h5 {
font-size: 14px;
}

h6 {
color: #777;
font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
color: #4183C4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
padding-left: 30px;
}

ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}

dl {
padding: 0;
}

dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}

dl dt:first-child {
padding: 0;
}

dl dt>:first-child {
margin-top: 0px;
}

dl dt>:last-child {
margin-bottom: 0px;
}

dl dd {
margin: 0 0 15px;
padding: 0 15px;
}

dl dd>:first-child {
margin-top: 0px;
}

dl dd>:last-child {
margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}

pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}

pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}

pre code, pre tt {
background-color: transparent;
border: none;
}

kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}

blockquote>:first-child {
margin-top: 0px;
}

blockquote>:last-child {
margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}

/* TABLES
=============================================================================*/

table th {
font-weight: bold;
}

table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}

table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}

table tr:nth-child(2n) {
background-color: #f8f8f8;
}

/* IMAGES
=============================================================================*/

img {
max-width: 100%
}
-->

pytho自动化开发 day06

Date:2016.02.20

    @南非波波

课程大纲:

day05

http://www.cnblogs.com/alex3714/articles/5161349.html

day06

http://www.cnblogs.com/alex3714/articles/5188179.html

一、模块回顾

1. os模块

2. sys模块

3. shutil模块

高级的 文件、文件夹、压缩包 处理模块

shutil.copyfileobj(fsrc, fdst[, length])

功能:将文件内容拷贝到另一个文件中,可以部分内容

shutil.copyfile(src, dst)

功能:仅拷贝文件

shutil.copymode(src, dst)

功能:仅拷贝权限,内容、组、用户均不变

shutil.copystat(src, dst)

功能:拷贝状态的信息,包括:mode bits, atime, mtime, flags

shutil.copy(src, dst)

功能:拷贝文件和权限

shutil.copy2(src, dst)

功能:拷贝文件和状态信息

1. zipfile

2. tarfile

4. shelve模块

二次封装pickle模块功能,对比pickle而言,shelve实现了按照‘键’来取值

示例:

#!/usr/local/env python3
'''
Author:@南非波波
Blog:http://www.cnblogs.com/songqingbo/
E-mail:qingbo.song@gmail.com
'''
import shelve name = ['swht','shen','test']
class Test(object):
def __init__(self,n):
self.n = n
t1 = Test(1234)
t2 = Test(123456) #存数据
# shelve_file = shelve.open('ret.txt')
# shelve_file['use'] = name
# shelve_file['t1'] = t1
# shelve_file['t2'] = t2
# shelve_file.close() #取数据
shelve_load = shelve.open('ret.txt')
a = shelve_load.get('use')
print(a)
b = shelve_load.get('t1')
print(b.n)
c = shelve_load.get('t2')
print(c.n)
shelve_load.close()

5.configparser模块

示例:

#!/usr/local/env python3
'''
Author:@南非波波
Blog:http://www.cnblogs.com/songqingbo/
E-mail:qingbo.song@gmail.com
'''
import configparser #生成文档
#["DEFAULT"]是一个全局模块,对所有的模块生效
'''
config = configparser.ConfigParser()
config["DEFAULT"] = {'ServerAliveInterval': '45',
'Compression': 'yes',
'CompressionLevel': '9'} config['bitbucket.org'] = {}
config['bitbucket.org']['User'] = 'hg'
config['topsecret.server.com'] = {}
topsecret = config['topsecret.server.com']
topsecret['Host Port'] = '50022' # mutates the parser
topsecret['ForwardX11'] = 'no' # same here
config['DEFAULT']['ForwardX11'] = 'yes'
with open('example.ini', 'w') as configfile:
config.write(configfile)
''' #查询
'''
config = configparser.ConfigParser()
config.read('example.ini')
print(config.sections()) #['bitbucket.org', 'topsecret.server.com']
if 'bitbucket.org' in config:
print('True')
print("['bitbucket.org']['User']:",config['bitbucket.org']['User'])
print("['bitbucket.org']['Compression']:",config['bitbucket.org']['Compression'])
for key in config['bitbucket.org']:
print(key)
'''
#读
'''
config = configparser.ConfigParser()
config.read('example.ini')
secs = config.sections()
print(secs) #['bitbucket.org', 'topsecret.server.com'] options = config.options('topsecret.server.com')
print(options) #['host port', 'forwardx11', 'compression', 'serveraliveinterval', 'compressionlevel'] item_list = config.items('bitbucket.org')
print(item_list) #[('compression', 'yes'), ('serveraliveinterval', '45'), ('compressionlevel', '9'), ('forwardx11', 'yes'), ('user', 'hg')] val = config.get('bitbucket.org','compression')
print(val)
''' #改写
config = configparser.ConfigParser()
config.read('example.ini') #实现从原来的文件中读取,删除[bitbucket.org]模块后将其他内容写到example_new.ini文件中
# sec = config.remove_section('bitbucket.org')
# config.write(open('example_new.ini', "w")) #添加[swht]模块
# sec = config.has_section('swht')
# sec = config.add_section('swht')
# config.write(open('example_new1.ini', "w"))

6. hashlib模块

该模块提供了多个算法对字符串进行加密操作。

示例代码:

#!/usr/local/env python3
'''
Author:@南非波波
Blog:http://www.cnblogs.com/songqingbo/
E-mail:qingbo.song@gmail.com
'''
import hashlib '''
#md5加密
md5num = hashlib.md5()
md5num.update(b"shendiaoxia1278@sohu.com")
print(md5num.hexdigest()) #7e023c9fafc96423da854e4923f466a1
''' '''
#sha1加密
sha1num = hashlib.sha1()
sha1num.update(b"shendiaoxia1278@sohu.com")
print(sha1num.hexdigest()) #dd8d5deaa16c2dde03785aac99943f8f75bfaba9
''' '''
#sha256加密
hash = hashlib.sha256()
hash.update(b"shendiaoxia1278@sohu.com")
print(hash.hexdigest()) #14b03e2271da2cc9b0cc3ff73727c6d3ba6ba17077470a92162f7b46c9d1d968
''' '''
#sha384加密
hash = hashlib.sha384()
hash.update(b"shendiaoxia1278@sohu.com")
print(hash.hexdigest()) #a27bbc0d66d6b8b00a7ebfcad662ebed385fe2098898dfe23b88ffa88e1b6565d82e7eee5c9950c90231d0c0aa286e00
''' '''
#sha512加密
hash = hashlib.sha512()
hash.update(b"shendiaoxia1278@sohu.com")
print(hash.hexdigest()) #42bb1886bba49373c8f8177fba32a58a1f31af7272219789db52776428789f4a39970da9a36fdef6ab76651ed9f07e0fa140e4fa7dd325cb52559389bb80ceab
'''

高级加密代码

'''
# import hashlib # ######## md5 #######
hash = hashlib.md5(b'898oaFs09f')
hash.update(b"shendiaoxia1278@sohu.com")
print(hash.hexdigest()) #2aa29d812ca08b39d96f9441775420ba
''' '''
import hmac #可以使用在用户登录的时候,使用用户输入的用户名和密码进行加密后作为用户的密码 hash = hmac.new(b"shendiaoxia1278@sohu.com")
hash.update(b"swht")
print(hash.hexdigest()) #c65d9bc3f37d6cfb9a9c959a18463bf4 '''

7. subprocess模块

1. python2.7

    import subprocess
#默认状态shell = False,必须使用一个列表的方式将shell命令传递进去
ret = subprocess.call(["ls", "-l"], shell=False)
#使用shell = True告诉subprocess模块对用户传入的shell命令不转义,即使用原生shell命令
ret = subprocess.call("ls -l", shell=True) 2. python3.5

8. logging模块

示例:

#!/usr/local/env python3
'''
Author:@南非波波
Blog:http://www.cnblogs.com/songqingbo/
E-mail:qingbo.song@gmail.com
'''
import logging # logging.warning("user [swht] is start the systerm!")
# logging.critical("server is down!")
#创建日志
logger = logging.getLogger('[Test-Log]')
logger.setLevel(logging.DEBUG) #创建一个控制台的handler并设置日志级别
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG) #创建一个文件的handler并设置日志级别
fh = logging.FileHandler("access.log")
fh.setLevel(logging.WARNING)
#创建日期格式 fomatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s',datefmt='%Y-%m-%d %H:%M:%S') #add formatter to ch and fh
ch.setFormatter(fomatter)
fh.setFormatter(fomatter) logger.addHandler(ch)
logger.addHandler(fh) # 'application' code
logger.debug('debug message')
logger.info('info message')
logger.warn('warn message')
logger.error('error message')
logger.critical('critical message') #输出格式:
'''
2016-02-20 16:53:27 [Test-Log] DEBUG debug message
2016-02-20 16:53:27 [Test-Log] INFO info message
2016-02-20 16:53:27 [Test-Log] WARNING warn message
2016-02-20 16:53:27 [Test-Log] ERROR error message
2016-02-20 16:53:27 [Test-Log] CRITICAL critical message
'''

二、面向对象编程

1. 面向对象的介绍

1.  不要写重复的代码
2. 代码易扩展,程序遵循易读、易改的原则

2. 面向对象的特性

1.  封装
2. 继承
1. 基类或父类或超类
2. 子类或派生类
一般情况下,一个子类只能有一个基类,但在python中,一个子类是可以继承多个基类,实现多重继承,可以通过多级继承来实现;继承的过程就是从一般到特殊的过程
3. 多态
实现接口的重用

3. 类、方法

类 class

示例:

#!/usr/local/env python3
'''
Author:@南非波波
Blog:http://www.cnblogs.com/songqingbo/
E-mail:qingbo.song@gmail.com
'''
class Role(object):
def __init__(self,name,role,weapon,life_value):
self.name = name
self.role = role
self.weapon = weapon
self.life_value = life_value
def buy_weapon(self,weapon):
self.weapon = weapon
print("%s 成功购买[%s]" % (self.name,weapon)) #实例化
p1 = Role('swht','p','A11',100)
t1 = Role('shen','t','A11',100) print("p1[weapon]初始值:",p1.weapon)
print("t1[weapon]初始值:",t1.weapon) #买枪行为
p1.buy_weapon("AK65")
t1.buy_weapon("AK60") print("p1[weapon]当前值:",p1.weapon)
print("t1[weapon]当前值:",t1.weapon)

作业:

模拟人生游戏

    1.  至少有两个不同的角色
2. 玩的过程中,必须有交互
3. 根据不同的交互产生不同的行为
4. 一定要用到面向对象编程的语法及思想

python开发学习-day06(模块拾忆、面向对象)的更多相关文章

  1. python开发学习-day05(正则深入、冒泡排序算法、自定义模块、常用标准模块)

    s12-20160130-day05 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  2. python开发学习-day02(元组、字符串、列表、字典深入)

    s12-20160109-day02 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  3. python开发学习-day01 (python安装与版本、字符串、字典、运算符、文件)

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  4. Python语言学习:模块

    一.模块 1. 模块(Module):以.py结尾的文件,包含python对象定义和python语句.使代码段更容易理解和使用. 模块分为两种:标准库(直接导入的库)和第三方库(需要下载安装的库). ...

  5. python开发学习-day07(面向对象之多态、类的方法、反射、新式类and旧式类、socket编程)

    s12-20160227-day07 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  6. python开发学习-day09(队列、多路IO阻塞、堡垒机模块、mysql操作模块)

    s12-20160312-day09 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  7. Python 开发学习路线

    第一阶段:Python 语言基础 数据类型 流程控制 常用模块 函数.迭代器.装饰器 递归.迭代.反射 面向对象编程 购物车程序 计算器程序开发 模拟人生游戏开发 第二阶段:网络编程 Socket c ...

  8. python开发学习-day10(select/poll/epoll回顾、redis、rabbitmq-pika)

    s12-20160319-day10 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  9. python基础学习笔记——模块

    自定义模块 我们今天来学习一下自定义模块(也就是私人订制),我们要自定义模块,首先就要知道什么是模块啊 一个函数封装一个功能,比如现在有一个软件,不可能将所有程序都写入一个文件,所以咱们应该分文件,组 ...

随机推荐

  1. OpenCV---人脸检测

    一:相关依赖文件下载 https://github.com/opencv/opencv   二:实现步骤(图片检测) (一)读取图片 image= cv.imread("./d.png&qu ...

  2. MongoDB-3.4集群搭建:分片

    概念 集群拥有三个节点: 分片(sharding),分发路由(query routers)和配置服务器 (config server) Shard 分片是存储了一个集合部分数据的MongoDB实例,每 ...

  3. 巧妙利用JQuery和Servlet来实现跨域请求

    在网上看到很多的JQuery跨域请求的文章,比较有意思.这里我发表一个Servlet与JQuery配置实现跨域的代码,供大家参考.不足之处请指教 原理:JavaScript的Ajax不可以跨域,但是可 ...

  4. 【BZOJ】1076 [SCOI2008]奖励关 期望DP+状压DP

    [题意]n种宝物,k关游戏,每关游戏给出一种宝物,可捡可不捡.每种宝物有一个价值(有负数).每个宝物有前提宝物列表,必须在前面的关卡取得列表宝物才能捡起这个宝物,求期望收益.k<=100,n&l ...

  5. 【BZOJ】4318: OSU! 期望DP

    [题意]有一个长度为n的01序列,每一段极大的连续1的价值是L^3(长度L).现在给定n个实数表示该位为1的概率,求期望总价值.n<=10^5. [算法]期望DP [题解]后缀长度是一个很关键的 ...

  6. javaScript基础语法介绍

    简介 JavaScript是一种脚本语言. (脚本,一条条的文字命令.执行时由系统的一个解释器,将其一条条的翻译成机器可识别的指令,然后执行.常见的脚本:批处理脚本.T-SQL脚本.VBScript等 ...

  7. 某团队线下赛AWD writeup&Beescms_V4.0代码审计

    还是跟上篇一样.拿别人比赛的来玩一下.  0x01 预留后门 连接方式: 0x02 后台登录口SQL注入 admin/login.php 在func.php当中找到定义的check_login函数 很 ...

  8. (转)USB的描述符及各种描述符之间的依赖关系

    全文链接:http://justmei.blog.163.com/blog/static/11609985320102421659260/?latestBlog 1 推荐 [原创] USB入门系列之七 ...

  9. 新一代的USB 3.0传输规格

    通用序列总线(USB) 从1996问世以来,一统个人电脑外部连接界面,且延伸至各式消费性产品,早已成为现代人生活的一部分.2000年发表的USB 2.0 High-speed规格,提供了480Mbps ...

  10. 64_t2

    texlive-biblatex-chem-doc-svn42065-33.fc26.2.no..> 24-May-2017 15:44 1044190 texlive-biblatex-che ...