模块的导入方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
demo1.py>> def test1(): print("demo1_test1")
def test2(): print("demo1_test2")
demo2.py>>
from demo1 import test1 as demo1_test1
def test1(): print("demo2_test1")
def test2(): print("demo2_test2")
test1() demo1_test1()
|
内置模块
sys模块
sys.argv与外部对接模块
1 2 3 4 5 6 7 8
|
import sys
res = sys.argv[1]
if res == 'yes': print("i am ok")
|
命令行
1 2 3
|
C:\Users\23242\AppData\Local\Temp\81.py1>python3 demo2.py yes
i am ok
|
其他sys的使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
import sys
print('111')
print('222')
|
os模块
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
import os
dirpath = 'Py\\doc' if not os.path.exists(dirpath): os.makedirs(dirpath)
res = os.path.join(os.getcwd(),'demo5') print(res)
|
time模块
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
import time
''' 2020-02-09 '''
import datetime
|
random模块
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
import random
''' 1、随机生成6位数验证码 1-1. 使用随机数字 1-2. 随机混合数字与字母 ''' def v_code(): code = '' for i in range(3):
li_range = [0,'1','A','B','C'] add_num = random.sample(li_range,2) add_num = map(str,add_num) code += ''.join(add_num)
print(code) v_code()
''' A --> ascii ord() 字符转ascii ch() ascii转字符 '''
def v_code(): code = '' for i in range(6): num = random.randrange(10) char = chr(random.randrange(65,91)) add_num = random.choice([num,char]) code += str(add_num) print(code) v_code()
|
Json模块
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
import json
j_data = '{"name" : "amy"}' print((json.loads(j_data))['name']) print(type(json.loads(j_data)))
|
IO模块
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
import io
import requests res = requests.get('https://img.zcool.cn/community/0170cb554b9200000001bf723782e6.jpg@1280w_1l_2o_100sh.jpg') print(type(res.content)) img=io.BytesIO(res.content) print(img.getvalue())
|
threading模块
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
import time import threading
def read(): while True: print('在%s,正在读书' %time.ctime()) time.sleep(1) def write(): for x in range(3): print('在%s,正在写字' %time.ctime()) time.sleep(1)
for i in range(1,10): t=threading.Thread(target=read).start() for i in range(1,10): t=threading.Thread(target=write).start()
|
FROM:gylq.gitee Author:孤桜懶契
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
点赞
https://cn-sec.com/archives/729963.html
复制链接
复制链接
-
左青龙
- 微信扫一扫
-
-
右白虎
- 微信扫一扫
-
评论