re module day17 classroom summary

Recalling the last lesson

os module

Interact with the operating system

sys module

Interact with the python interpreter

json module

Cross-platform data exchange, json string

pickle module

Python interactive store all types of data, in order to python file and python files

logging module

Logging

Today plant science

package

  1. == module package, the package is brought introduction
  2. Package containing __init__.pythe folder; leader packet is introduced__init__
  3. Packet must be treated as module file import file search path module m1.py/m2.py execution file path to prevail

time module

Offers three different types of time (for the most important time stamp), three different types of time can be interchangeable

# 时间戳形式
print(time.time()) 
# 格式化时间
print(time.strftime('%Y-%m-%d %X'))
# 结构化时间
print(time.localtime())

time.sleep () allow a program to sleep for a few seconds

datetime module

Time of addition and subtraction

import datetime

now = datetime.datetime.now()
print(now)

# 默认3天
print(now + datetime.timedelta(3))
# 加3周
print(now + datetime.timedelta(weeks=3))
# 加3小时
print(now + datetime.timedelta(hours=3))
# 减3小时
print(now - datetime.timedelta(hours=3))

random module

random number

random.random()

0-1 specific number

random.randint(1,3)

Integer 1-3

lt=[1,2,3]
random.shuffle(lt)# 打乱列表
random.choice(lt)# 随机选择一个

random.seed()

Only a random

hashlib module and the module hmac

hashlib module

encryption

m = hashlib.md5()
m.update(b'hello')
m.update(b'hello')
print(m.hexdigest())


m = hashlib.md5()
m.update(b'hellohello')
print(m.hexdigest())
  1. Results are always the same length of the string
  2. Superposition

hmac module

Encryption, salt processing

m = hmac.new(b'123')
m.update(b'hellow')
print(m.hexdigest())

typing module

A function associated with the control function parameter data type, a data type other than the type of underlying data

requests module

Reptiles generally used for crawling data, the browser get analog data transmission request url

#用法
import requests
res=requests.get(url)
data=res.text
print(data)

re module

String to find String meet certain characteristics

```python

Find all

findall

^: ... begins with

res = re.findall('^ab', s)
print(res)
res = re.findall('^bc', s)
print(res)

$: Ends with ..

s = 'abcdabc'
res = re.findall('bc$', s)
print(res)

: Any character

s = 'abc红abc'
res = re.findall('abc.', s)
print(res)

\ D: Digital

s = 'skld2342ljk'
res = re.findall('\d', s)
print(res)

\ W: non-empty, alphanumeric underscore

s = 'skld_23 42ljk'
res = re.findall('\w', s)
print(res)

\ S: empty spaces / \ t / \ n

s = 'skld_23 42ljk'
res = re.findall('\s', s)
print(res)

\ D: Non-digital

s = 'skld2342ljk'
res = re.findall('\D', s)
print(res)

\ W: Empty

s = 'skld_23 42ljk'
res = re.findall('\W', s)
print(res)

\ S: non-empty

s = '

Guess you like

Origin www.cnblogs.com/shin09/p/11604805.html