1.config 模块

 import configparser

 conf = configparser.ConfigParser()
conf["DEFAULT"] = {'ServerAliveInterval': '',
'Compression': 'yes',
'CompressionLevel': ''}
conf['wwwwwwwww'] = {}
conf['wwwwwwwww']['user'] = 'baidu'
conf['topsecret.server.com'] = {}
topsecret = conf['topsecret.server.com']
topsecret['Host Port'] = ''
with open('conf.ini','w') as f:
f.write(conf)

2.hashlib操作

 import hmac
h = hmac.new(b'hsc')
h.update(b'')
print(h)

3.random模块

 import random
print(random.random())
print(random.randint(1,2)) #0,1,2 随机
print(random.randrange(1,2))#0,1 随机 checkcode = ''
for i in range(6):
current = random.randrange(0,6)
if current != i:
temp = chr(random.randint(65,90))
else:
temp = random.randint(0,9)
checkcode += str(temp)
print(checkcode)

4.shelve模块

 import shelve

 d = shelve.open('shelve_test')

 def stu_data(name,age):
print("register stu",name,age)
name = ["hsc","xjp","abm"]
info = {"name":"hsc","age":18} d["test"] = name
d["info"] = info
d['func'] = stu_data

5.shutil模块

 import shutil

 # f1 = open("random mod .py")
# f2 = open("random_new .py",'w')
# shutil.copyfileobj(f1,f2) # shutil.copyfile("笔记",r'd:\123')
shutil.make_archive('www','gztar',root_dir=r'C:\Users\heshaochuan\PycharmProjects\py_s15\day6')

6. logging模块

 import logging

 log_test = logging.getLogger('TEST')
logging.basicConfig(filename='wwwwwwwwww.log',level=logging.INFO)
logging.debug('mthgh')
logging.info('')

7.re模块

常用正则表达式符号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'.'     默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行
'^'     匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r"^a","\nabc\neee",flags=re.MULTILINE)
'$'     匹配字符结尾,或e.search("foo$","bfoo\nsdfsf",flags=re.MULTILINE).group()也可以
'*'     匹配*号前的字符0次或多次,re.findall("ab*","cabb3abcbbac")  结果为['abb''ab''a']
'+'     匹配前一个字符1次或多次,re.findall("ab+","ab+cd+abb+bba") 结果['ab''abb']
'?'     匹配前一个字符1次或0
'{m}'   匹配前一个字符m次
'{n,m}' 匹配前一个字符n到m次,re.findall("ab{1,3}","abb abc abbcbbb") 结果'abb''ab''abb']
'|'     匹配|左或|右的字符,re.search("abc|ABC","ABCBabcCD").group() 结果'ABC'
'(...)' 分组匹配,re.search("(abc){2}a(123|456)c""abcabca456c").group() 结果 abcabca456c
 
 
'\A'    只从字符开头匹配,re.search("\Aabc","alexabc") 是匹配不到的
'\Z'    匹配字符结尾,同$
'\d'    匹配数字0-9
'\D'    匹配非数字
'\w'    匹配[A-Za-z0-9]
'\W'    匹配非[A-Za-z0-9]
's'     匹配空白字符、\t、\n、\r , re.search("\s+","ab\tc1\n3").group() 结果 '\t'
 
'(?P<name>...)' 分组匹配 re.search("(?P<province>[0-9]{4})(?P<city>[0-9]{2})(?P<birthday>[0-9]{4})","371481199306143242").groupdict("city") 结果{'province''3714''city''81''birthday''1993'}

Python之路,day6-Python基础的更多相关文章

  1. Python之路,Day6 - Python基础6

    本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve xml处理 yaml处理 configpars ...

  2. Python之路,Day4 - Python基础4 (new版)

    Python之路,Day4 - Python基础4 (new版)   本节内容 迭代器&生成器 装饰器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 ...

  3. (转)Python之路,Day6 - 面向对象学习

    本节内容:   面向对象编程介绍 为什么要用面向对象进行开发? 面向对象的特性:封装.继承.多态 类.方法.     引子 你现在是一家游戏公司的开发人员,现在需要你开发一款叫做<人狗大战> ...

  4. Python之路,Day1 - Python基础1

    本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...

  5. 转:Python之路,Day6 - 面向对象学习

    这篇文章写的不错,转来收了 转自:http://www.cnblogs.com/alex3714/articles/5188179.html   本节内容:   面向对象编程介绍 为什么要用面向对象进 ...

  6. 十一Python之路,Day6 - 面向对象学习

      本节内容:   面向对象编程介绍 为什么要用面向对象进行开发? 面向对象的特性:封装.继承.多态 类.方法.     引子 你现在是一家游戏公司的开发人员,现在需要你开发一款叫做<人狗大战& ...

  7. Python之路,Day1 - Python基础1(转载Alex)

    本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...

  8. Python之路,Day1 - Python基础1 --转自金角大王

    本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...

  9. Python之路,Day1 - Python基础1 介绍、基本语法、流程控制

    本节内容 1.python介绍 2.发展史 3.python 2.x or python 3.x ? 4.python 安装 5.第一个程序 Hello World 程序 6.变量 7.用户输入 8. ...

  10. Python之路:Python简介

    Python前世今生 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间他为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承 ...

随机推荐

  1. 源码编译安装 MySQL 5.5.x 实践

    1.安装cmakeMySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具.因此,我们首先要在系统中源码编译安装cmake工具. # wget ht ...

  2. jsp提交表单数据乱码,内置对象,以及过滤器

    jsp提交表单数据乱码解决方案 通过form表单给服务器提交数据的时候,如果提交的是中文数据,那么可能会出现乱码,如果表单的请求方式是post请求,那么可以使用如下方案解决乱码: 在调用getPara ...

  3. android.app.Activity阅读摘要,有时候会不会需要保持一些现场数据呢? 想让系统帮你退出到后台或者挂掉前做些前置保持工作吗,重点参考吧:

    * * @param savedInstanceState If the activity is being re-initialized after * previously being shut ...

  4. gantt甘特图的制作过程

    甘特图主要是用来做项目管理的,可以清楚的看到任务间的逻辑关系,任务与时间关系和任务间并行关系. 在甘特图中,横轴方向表示时间,纵轴方向并列着活动列表.图表内可以用线条.数字.文字代号等来表示计划(实际 ...

  5. C#利用摄像头拍照功能实现

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. Your build settings specify a provisioning profile with the UUID, no provisioning profile

    在Archive项目时,出现了“Your build settings specify a provisioning profile with the UUID “”, however, no suc ...

  7. Redis 常用链接

    安装部署 http://www.linuxidc.com/Linux/2014-05/101979.htm 更改访问权限配置(如密码,可访问地址):http://www.jb51.net/articl ...

  8. Mac、Linux更换命令行svn diff为P4Merge、vimdiff

    2015-01-21 21:25:52 这里先把那个程序员大神的博客地址贴一下(PS:大神,我不是为了抄袭哦,真是怕自己忘记了),http://www.ccvita.com/445.html,里面还有 ...

  9. CEPH经常出现slow request的排查解决

    现象: 通过ceph -w日志经常发现有request blocked的问题(如果虚拟机系统跑在ceph上时,就会发现严重的卡顿现象) 排查: 1.通过dstat未发现有明显的瓶颈 (dstat -t ...

  10. android 保存文件的各种目录列表

    一般的,我们可以通过context和Environment来获取要保存文件的目录 ($rootDir) +- /data -> Environment.getDataDirectory() | ...