Python之路,day6-Python基础
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基础的更多相关文章
- Python之路,Day6 - Python基础6
本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve xml处理 yaml处理 configpars ...
- Python之路,Day4 - Python基础4 (new版)
Python之路,Day4 - Python基础4 (new版) 本节内容 迭代器&生成器 装饰器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 ...
- (转)Python之路,Day6 - 面向对象学习
本节内容: 面向对象编程介绍 为什么要用面向对象进行开发? 面向对象的特性:封装.继承.多态 类.方法. 引子 你现在是一家游戏公司的开发人员,现在需要你开发一款叫做<人狗大战> ...
- Python之路,Day1 - Python基础1
本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...
- 转:Python之路,Day6 - 面向对象学习
这篇文章写的不错,转来收了 转自:http://www.cnblogs.com/alex3714/articles/5188179.html 本节内容: 面向对象编程介绍 为什么要用面向对象进 ...
- 十一Python之路,Day6 - 面向对象学习
本节内容: 面向对象编程介绍 为什么要用面向对象进行开发? 面向对象的特性:封装.继承.多态 类.方法. 引子 你现在是一家游戏公司的开发人员,现在需要你开发一款叫做<人狗大战& ...
- Python之路,Day1 - Python基础1(转载Alex)
本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...
- Python之路,Day1 - Python基础1 --转自金角大王
本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...
- Python之路,Day1 - Python基础1 介绍、基本语法、流程控制
本节内容 1.python介绍 2.发展史 3.python 2.x or python 3.x ? 4.python 安装 5.第一个程序 Hello World 程序 6.变量 7.用户输入 8. ...
- Python之路:Python简介
Python前世今生 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间他为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承 ...
随机推荐
- 完整的分页存储过程以及c#调用方法
高效分页存储过程 USE [db] GO /****** 对象: StoredProcedure [dbo].[p_Page2005] 脚本日期: // :: ******/ SET ANSI_NUL ...
- ajax容易忽视的细节
用了很长时间的ajax,自己也写过原生ajax请求,但是发现自己对于ajax理解仍然非常肤浅. 1.ajax请求后,服务器会返回数据,返回头中content-type直接影响responseXML,r ...
- LeetCode 20 -- Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- dsaf
fdsafds fdsa fds f dsa
- Maven构件解析(转)
文章转自http://gavinwind2000.iteye.com/blog/2290652 谢谢博主的总结! 在Maven中,任何一个依赖.插件或者项目构建的输出,都可以称之为构件. Maven在 ...
- 【LeetCode OJ】Validate Binary Search Tree
Problem Link: https://oj.leetcode.com/problems/validate-binary-search-tree/ We inorder-traverse the ...
- 如何在MATLAB R2010a 中使用Visual C++ 2010编译器
安装补丁VS2012MEXSupport.zip http://www.mathworks.com/matlabcentral/answers/93013-how-can-i-use-microsof ...
- [.NET] CErrStack 方便地管理错误或异常
Option Explicit On Option Strict On Imports System.Reflection Imports System.Diagnostics Public Stru ...
- [C++] 自己实现快速memcpy
仅在Win32上使用,Win64上不允许内嵌汇编= = __declspec(naked) void* __stdcall __memcpy ( __in void* Dest, // ebp+0x0 ...
- win32自绘按钮,使用GDI+(一)
第一次写随笔,我本来想将win32窗口的标题栏设置成渐变色,像这样的效果 但发现找不到设置标题栏属性的api,SetWindowLong也只是增减窗口的固定的样式而已.所以想到一个思路,把标题栏去掉, ...