Fork me on GitHub
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 26 下一页
摘要: # ### 压缩模块 zipfile # (1) 创建一个zip压缩包 import zipfile # zip_deflated 代表是压缩的意思 # 打开压缩包 zf = zipfile.ZipFile("ceshi1136.zip","w",zipfile.ZIP_DEFLATED) print(zf) # 写入文件 # write("路径","别名") zf.write("/bin/... 阅读全文
posted @ 2019-05-24 22:26 MR_黄Python之路 阅读(488) 评论(0) 推荐(0) 编辑
摘要: # ### 计算任意文件夹的大小 import os ''' pathvar = "/mnt/hgfs/gongxiang_16/day17/ceshi100" lst = os.listdir(pathvar) print(lst) # 遍历所有的文件和文件夹,计算文件的大小 size = 0 for i in lst: # print(i) path_new = os.path.j... 阅读全文
posted @ 2019-05-24 22:25 MR_黄Python之路 阅读(325) 评论(0) 推荐(0) 编辑
摘要: # ### os.path import os #abspath() 将相对路径转化为绝对路径 *** res = os.path.abspath(".") print(res) #basename() 返回文件名部分 *** pathvar = "/mnt/hgfs/gongxiang_16/day16/2.py" res = os.path.basename(pathvar) pr... 阅读全文
posted @ 2019-05-24 22:21 MR_黄Python之路 阅读(225) 评论(0) 推荐(0) 编辑
摘要: # ### os 对系统进行操作 import os #system() 在python中执行系统命令 # os.system("touch ceshi1.txt") #linux # os.system("ifconfig") # os.system("mspaint") # windows # os.system("ipconfig") #popen() 执行系统命令返回对象,通过... 阅读全文
posted @ 2019-05-24 22:18 MR_黄Python之路 阅读(239) 评论(0) 推荐(0) 编辑
摘要: # ### time 时间模块 import time #time() 获取本地时间戳 res = time.time() print(res) #mktime() 通过[时间元组]获取[时间戳] (参数是时间元组) ttp = (2019,5,16,10,55,30,0,0,0) res = time.mktime(ttp) print(res) #localt... 阅读全文
posted @ 2019-05-24 22:17 MR_黄Python之路 阅读(186) 评论(0) 推荐(0) 编辑
摘要: # ### math 数学模块 import math #ceil() 向上取整操作 (对比内置round) res = math.ceil(6.0001) # 注意精度损耗 print(res) #floor() 向下取整操作 (对比内置round) res = math.floor(3.5) res = math.floor(3.9999999) print(res) #pow() ... 阅读全文
posted @ 2019-05-24 22:16 MR_黄Python之路 阅读(188) 评论(0) 推荐(0) 编辑
摘要: # ### random 随机模块 import random #random() 获取随机0-1之间的小数(左闭右开) res = random.random() # 0 当取0时 4 4+-6*(0~1) => 当取1时 -2 (1是取不到的) 所以: -2 < x <=4 ''' #choice() 随机获取序列中的值(多选一) listvar = ["周杰伦","王文","... 阅读全文
posted @ 2019-05-24 22:16 MR_黄Python之路 阅读(135) 评论(0) 推荐(0) 编辑
摘要: # ### json """ json 模块能够转化的数据类型如下: int float bool str list tuple dict None 8个数据类型可以序列化 json数据类型的提出,是让不同的语言之间形成数据交流 pickle返回的是二进制的字节流,它是用来进行数据的传输和存储的. json 序列化成一个字符串 pickle 序列化成一个字节流 """ import jso... 阅读全文
posted @ 2019-05-24 22:15 MR_黄Python之路 阅读(319) 评论(0) 推荐(0) 编辑
摘要: # ### pickle 序列化模块 ''' 把不能够直接存储的数据,变得可存储就是序列化 把存储好的数据,转化成原本的数据类型,叫做反序列化 php: 序列化与反序列化 serialize unserialize ''' # 导入pickle 模块 => 模块.方法() import pickle #dumps 把任意对象序列化成一个bytes lst = [1,2,3,4,4,5] r... 阅读全文
posted @ 2019-05-24 22:14 MR_黄Python之路 阅读(237) 评论(0) 推荐(0) 编辑
摘要: # abs 绝对值函数 intvar = -9 res = abs(intvar) print(res) # round 四舍五入 (n.5 n为偶数则舍去 n.5 n为奇数,则进一!) '''奇进偶不进 , 只在n.5的情况下发生''' a = 5.34 a = 6.5 a = 5.5 a = 6.56 a = 17.51 print(round(a)) # sum 计算... 阅读全文
posted @ 2019-05-24 22:13 MR_黄Python之路 阅读(179) 评论(0) 推荐(0) 编辑
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 26 下一页