码迷,mamicode.com
首页 > 其他好文 > 详细

2021/6/2

时间:2021-06-03 17:51:12      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:name   uuid   日期   val   对象   imp   转义   pop   getcwd   

‘‘‘
os模块
目录操作
.removedirs(dirname)
.makedirs(dirname)
.mkdir(dirname)
.rmdir(dirname)
.chdir(dirname)
.listdir(dirname)
属性
.environ
.name
.sep
.linesep
.pathsep

文件操作
.remove(file_name)
目录/文件操作
.rename(oldname,newname)
.stat()
获取
.getcwd()
.getpid()
.getppid()
.cpu_count()
命令
.system()
.popen().read()
os.path
对路径的操作
.abspath()
.split()
.basename()
.dirname()
.splitext()
判断
.isdir()
.isfile()
.exists()
.isabs()
获取
getctime
getmtime
getatime
getsize
合并路径
.join(os.path.abspath(), path)

sys模块
属性
.version
.platform
.path
.stdin
.stdout
.stderr
方法
sys.argv[]
sys.exit()
time模块
timestamp -->
format string
ctime
struct_time
localtime
gmtime
format string -->
struct_time
striptime

struct_time --> timestamp
mktime
format string
strftime
asctime

time.sleep
time.time

%Y %m %s %H %M %S
tm_year mon mday hours minutes seconds yday isdst
datetime模块
datetime(year, month, day, hours, minutes, seconds)
.now()
.today()
.utcnow()
date(year, month, day)
.today()
time(hours, minutes, seconds)

日期对象
.year() .month() .day() .weekday() .isoweekday()

timedelta对象
日期对象 + - 日期对象 = timedelta对象
日期对象 + - timedelta对象 = 日期对象
random模块
.random() 0-1
.randint(a, b)
.uniform(a, b)
.randrange(start, stop, step)
.choice([])
.sample([], int)
.shuffle(list)
math模块
.fabs()
.ceil()
.floor()
.pi
.pow(a, b)
sin()
cos()
tan()
json模块
dumps(obj)
loads(json)
dump(obj, file)
load(file)
pickle模块
dumps(obj)
loads(pickle)
dump(obj, file)
load(file)
collections模块
namedtuple()
a = namedtuple(‘a‘, ‘字段‘)
b = a(元组)
a.字段名
deque()
.append()
.pop()
.appendleft()
.popleft()
OrderedDict(**kwargs, [(k, v),...])
defaultdict(func, **kwargs, [(k, v),...])
Counter(iterable) {}
hashlib模块
hashlib.md5/sha1/sha224/sha256/sha384/(byte)
hexdigest()
configparser模块
对 ini 文件的操作

三板斧
a = configparser.ConfigParser()
a.read(‘.ini‘, encoding=‘‘)
a.write(open())
创建
a[‘section‘] = {‘option‘: ‘value‘,...}
增加section
.add_section(‘section‘)
删除
.remove_section(‘section‘)
.remove_option(‘section‘, ‘option‘)
修改option-value
.set(‘section‘, ‘option‘, ‘value‘)
查看
a[‘section‘][‘option‘]
.sections()
.options(‘section‘)
.get(‘section‘, ‘option‘)
getint
getfloat
getboolean
.items(‘section‘)
判断
has_section(‘section‘)
has_option(‘section‘, ‘option‘)
struct模块
pack(‘‘, data)
unpack(‘‘, data)
CSV模块
a = writer(open)
.writerow([])
.writerows([[]])
.reader(open())
io模块
from io import StringIO, BytesIO
a = StringIO()
a.write(‘zhangzhuowei‘)
print(a.getvalue())
b = BytesIO()
b.write(b‘zhangzhuowei‘)
print(b.getvalue())
subprocess模块
Popen(‘‘, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
uuid模块
uuid1()
copy模块
copy()
.deepcopy()
hmac模块
.new(key, byte)
.hexdigest()

django中的模块
importlib
importlib.import_module(‘包名.文件‘)

re模块
re.match类
match()
search()
finditer()
findall()
fullmatch()
属性
.re
.string
.pos
.endpos
.lastindex
.lastgroup

方法
.group(index)
.groups()
.groupdict()
.span(group)
.start(group)
.end(group)
.expand(template)

re.compile(re)

正则修饰符
re.I 忽略大小写
re.S . 匹配包括 \n
re.M 多行匹配 影响 ^ $

正则表达规则
1. 数字和字母代表它本身
2. 标点符号具有正则意义
3. 注意转义字符
4. 可以使用\取消字符的正则意义

正则匹配模式
非打印字符
\t \cI
\n \cJ
\v \cK
\f \cL
\r \cM
\s 空白字符
\S 非空白字符
\d 数字 0-9
\D 非数字 [^0-9]
\w 数字、中文、字母、下划线
\w 非数字、中文、字母、下划线
特殊字符
()
分组,0代表整个正则,1代表第一个分组
[]
匹配括号内任意一个字符
{}
限定符
| 或
. 除去 \n 的任何字符
\ 转义
定位符
^
在[] 中代表取反
$
\d 单词边界字符
\D 非单词边界
限定符
* 0 ~ 无穷大
+ 1 ~ 无穷大
? 0 ~ 1
{n}
{n,}
{,m}
{n,m}
正则替换
sub(re, func/str, str)
贪婪模式
对于限定符
(?P<name>)

‘‘‘

2021/6/2

标签:name   uuid   日期   val   对象   imp   转义   pop   getcwd   

原文地址:https://www.cnblogs.com/zhangzhuowei/p/14843448.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!