首页
登录
搜索
登录
搜索
emer
累计撰写
197
篇文章
累计收到
496
条评论
首页
栏目
首页
登录
自定义幻灯片
最新文章
2019-10-14
Python学习笔记之压缩模块
# zipfile模块 # import zipfile # 创建压缩包 # zf = zipfile.ZipFile('/Users/zhangyutong/Desktop/test.zip', 'w', zipfile.ZIP_DEFLATED); # 添加文件到压缩包 # zf.write('/Users/屏幕快照 2019-10-13 下午12.40.40.png','屏幕快照 2019-10-13 下午12.40.40.png') # 关闭压缩包 # zf.close() # 解压压缩包 import zipfile; zf = zipfile.ZipFile('/Users/zhangyutong/Desktop/test.zip','r') zf.extractall('/Users/zhangyutong/Desktop/hello/fdsafsdfassa'); zf.close();
2019年-10月-14日
59 阅读
0 评论
未分类
2019-9-23
Python学习笔记之shutil模块
# shutil 模块 import shutil # copyfileobj(源文件, 目的文件[, length = 16 * 1024]) length = 一次读取多少个字符 # fp1 = open('./1235/1.txt', 'r') # fp2 = open('./1235/2.txt', 'w') # shutil.copyfileobj(fp1, fp2) # copyfile(src, dst) 仅复制文件内容 # shutil.copyfile('./1235/1.txt','./1235/22.txt') # copymode(src, dst) # shutil.copymode('./1235/1.txt', './1235/2.txt') # copy(src, dst) 复制文件和权限 # shutil.copy('./1235/1.txt', './1235/2132123.text') # copy2(src, dst) 复制文件和权限,包含用户组 时间等 # copytree(src, dst) 复制文件夹里面的所有内容 递归拷贝 # rmtree('') 删除文件夹所有内容 递归删除 # move() 移动文件或文件夹
2019年-9月-23日
109 阅读
0 评论
未分类
2019-9-23
Python学习笔记之os文件操作模块
# os 模块对文件的操作 import os os.chdir('/Users/zhangyutong/Desktop/1235') # 切换工作目录 # mknod() 创建文件 import os # mknod() 创建文件 # os.mknod('132.text') # remove() 删除文件 # os.remove('1.php') # mkdir() 创建目录 # os.mkdir('3333') # rmdir() 删除目录 # os.mkdir('3333') # rename() 重命名 文件或 目录 # os.rename('3333', '2222')
2019年-9月-23日
59 阅读
0 评论
未分类
2019-9-23
Python学习之目录递归
# import os # def computedDirSize(url = ''): # n = 0 # if not os.path.exists(url): # return '文件不存在' # for i in os.listdir(url): # if os.path.isfile(os.path.join(url,i)): # n += os.path.getsize(os.path.join(url,i)) # else: # n += computedDirSize(os.path.join(url,i)) # return n # res = computedDirSize('/Users/zhangyutong/Downloads/第一期python基础/') # print(res) # 目录树 import os def dirtree(url, nbsp = ''): count = 0 sizecount = 0 for i in os.listdir(url): if os.path.isfile(os.path.join(url, i)): count += 1 sizecount += os.path.getsize(os.path.join(url, i)) print('%s[文件]%s --[大小:%d字节]' % (nbsp, i, os.path.getsize(os.path.join(url, i)))) elif os.path.isdir(os.path.join(url, i)): print('%s[目录]%s' % (nbsp, i)) temp = dirtree(os.path.join(url, i), nbsp + ' ') count += temp[0] sizecount += temp[1] return [count,sizecount] count = dirtree('/Users/zhangyutong/Downloads/第一期python基础/') judge = '共计文件%d个, 文件大小共%dBytes' % (count[0], count[1]) print(judge)
2019年-9月-23日
53 阅读
0 评论
未分类
2019-9-22
Python学习笔记之os路径模块
# os.path 路径模块 import os # abspath() 将相对路径转为绝对路径 res = os.path.abspath('.') print(res) # /Users/root/Desktop # basename() 返回文件名部分 res = os.path.basename('/hello/world/zhangyutong.txt') print(res) # zhangyutong.txt # dirname() 返回路径部分 res = os.path.dirname('/hello/world/zhangyutong.txt') print(res) # /hello/world # split() 将路径拆成单独的文件部分 和 路径部分 元组形式 res = os.path.split('/hello/world/zhangyutong.txt') print(res) # ('/hello/world', 'zhangyutong.txt') # join() 可以将多个路径 或 文件 组成一个新的路径 不同的系统加上不同的/ 或 \ dirname1 = '/usr' dirname2 = 'hello' dirname3 = 'world' filename = 'zhangyutong.txt' res = os.path.join(dirname1,dirname2,dirname3,filename) print(res) # /usr/hello/world/zhangyutong.txt # splitext() 将路径分割成后缀和其他部分 path = '/hello/world/zhangyutong.text' res = os.path.splitext(path) print(res) # ('/hello/world/zhangyutong', '.text') # getsize() 获取文件大小 res = os.path.getsize('/Users/zhangyutong/Desktop/1235/1') print(res) # 8 # isdir() 检测路径是否是文件夹 res = os.path.isdir('/Users/zhangyutong/Desktop/1235/1') print(res) # False # isfile() 检测是否是一个文件 res = os.path.isfile('/Users/zhangyutong/Desktop/1235/1') print(res) # True # islink() 检测是否是一个链接 res = os.path.islink('/Users/zhangyutong/Desktop/999') print(res) # False # getctime() 获取文件的创建时间 在 Linux 获取的是 最近改动时间 res = os.path.getctime('/Users/zhangyutong/Desktop/1235/1') print(res) # 1569156625.1559868 import time print(time.ctime(res)) # Sun Sep 22 20:50:25 2019 # exists() 检测路径是否存在 res = os.path.exists('/Users/zhangyutong/Desktop/') print(res) # True # isabs() 检测是否是绝对路径 res = os.path.isabs('/123') print(res) # True
2019年-9月-22日
62 阅读
0 评论
未分类
2019-9-22
Python学习笔记之OS模块
# os 模块 import os # 对系统进行操作的模块 # system() 在python 执行系统命令 os.system('mkdir ./1235') # res = os.system('rm -rf ./1235') # print(res) # 获取根目录下的所有文件 res = os.listdir('/') print(res) # ['home','dev','bin','usr','var'] # getcwd() 获取当前文件所在的目录 res = os.getcwd() print(res) # /Users/root/Desktop # chdir() 修改当前文件默认目录 os.chdir('/Users/zhangyutong/Desktop/1235') os.system('touch 1.php') # environ 获取或修改环境变量 res = os.environ['PATH'] # 获取path路径 # 把自定义的路径加入到系统环境变量中 os.environ['PATH'] = os.environ['PATH'] + ':/Users/zhangyutong/Desktop/1235' res = os.system('1') res = os.name print(res) # posix 代表Mac 或 Linux nt代表windows res = os.sep print(res) # / 代表系统分隔符号 res = os.linesep print(repr(res)) # '\n' res = os.environ print(res)
2019年-9月-22日
73 阅读
0 评论
未分类
2019-9-22
Python学习笔记之时间模块
# 时间模块 import time # 获取当前时间戳 res = time.time() print(res) # 1569152220.355634 # 获取当前时间 res = time.ctime() print(res) # Sun Sep 22 19:38:40 2019 # 格式化时间戳 res = time.ctime(1569152220.355634) print(res) # Sun Sep 22 19:37:00 2019 # 获取本地时间元组 res = time.localtime() print(res) # time.struct_time(tm_year=2019, tm_mon=9, tm_mday=22, tm_hour=19, tm_min=40, tm_sec=34, tm_wday=6, tm_yday=265, tm_isdst=0) # 通过元组获取时间戳 res = time.mktime(( 2019, 9, 28, 10, 10, 10, 0, 0, 0)) print(res) # 1569636610.0 # 通过时间元组 获取 时间字符串 res = time.asctime(( 2019, 9, 28, 10, 10, 10, 0, 0, 0)) print(res) # Mon Sep 28 10:10:10 2019 # sleep 睡眠等待 # time.sleep(2) # 单位为秒数 print('睡醒了吗?') # strftime(格式化字符串,时间元组) 格式化字符串 res = time.strftime('现在是%Y年%m月%d日%H点%M分%S秒',time.localtime()) print(res) # strptime() 将字符串里面的时间提取出来 res = time.strptime('现在是2019年09月22日20点01分59秒','现在是%Y年%m月%d日%H点%M分%S秒') print(res) # time.struct_time(tm_year=2019, tm_mon=9, tm_mday=22, tm_hour=20, tm_min=1, tm_sec=59, tm_wday=6, tm_yday=265, tm_isdst=-1) # perf_counter() 用于计算程序运行时间 start_time = time.perf_counter() n = 0 while n < 999: n+=1 end_time = time.perf_counter() print(end_time - start_time)
2019年-9月-22日
61 阅读
0 评论
未分类
2019-9-22
Python学习笔记之随机模块
# 随机模块 import random # random 获取一个0<=n<1之间的小数 res = random.random() print(res) # 0.3550163662210797 # randrange() 获取一个指定范围内的整数 (开始值,结束值,间隔值) res = random.randrange(10,100,20) print(res) # 10 # randint() 获取一个指定范围的整数 res = random.randint(1,10) print(res) # 10 # uniform() 获取指定范围的小数 res = random.uniform(1,3) print(res) # 2.31351965563249 # choice() 随机获取列表中的值 listvar = [1,2,3,4,5,6,7,8] res = random.choice(listvar) print(res) # 7 # shuffle() 随机打乱序列中的值 listvar = [1,2,3,4,5,6] res = random.shuffle(listvar) print(listvar) # [5, 1, 4, 6, 2, 3]
2019年-9月-22日
47 阅读
0 评论
未分类
2019-9-22
Python学习笔记之数学模块
# 数学模块 # ceil() 向上取整 (对比内置round()) import math res = math.ceil(3.0001) print(res) # 4 # floor() 向下取整 (对比内置round()) res = math.floor(3.9999) print(res) # 3 # pow() 计算一个数的N次方 (对比内置pow) res = math.pow(2,3) print(res) # 8.0 # sqrt() 开平方运算 res = math.sqrt(9) print(res) # 3.0 # fabs() 计算绝对值 (对比内置abs) res = math.fabs(-100) print(res) # 100.0 # modf() 将一个数值拆分成整数和小数两个部分组成元组 res = math.modf(13.3) print(res) # (0.3000000000000007, 13.0) # copysign() 将参数的第二个数正负括号拷贝给第一个 res = math.copysign(3,-10) print(res) # -3.0 # fsum() 将容器中的数计算求和 listvar = [1,2,3,4,5,6,7,8] res = math.fsum(listvar) print(res) # 36.0 # 圆周率pi res = math.pi print(res) # 3.141592653589793
2019年-9月-22日
73 阅读
0 评论
未分类
2019-9-22
Python学习笔记之序列化模块
# pickle 序列化模块 ''' 序列化:把不能直接存储的数据转换为可以存储的这个过程叫着序列化 反序列化:把存储的内容拿出来转化为原来的数据类型,叫反序列化 函数: dumps() 把任意一个对象序列化成一个bytes loads() dump() load() ''' dictvar = {'pikaqiu':'皮卡丘','miaowazhongzi': '妙蛙种子', 'xiaohuolong': '小火龙'} import pickle res = pickle.dumps(dictvar) print(res) # b'\x80\x03}q\x00(X\x07\x00\x00\x00pikaq... res = pickle.loads(res) print(res) # {'pikaqiu': '皮卡丘', 'miaowazhongzi': '妙蛙种子', 'xiaohuolong': '小火龙'} def func () : print('张宇童 - 前沿技术博客') res = pickle.dumps(func) print(res) res = pickle.loads(res) res() with open('0922.txt', 'wb+') as fp: pickle.dump(func,fp) with open('0922.txt', 'rb+') as fp: res = pickle.load(fp) res() # 张宇童 - 前沿技术博客
2019年-9月-22日
63 阅读
0 评论
未分类
7
8
9
10
11