上一页 1 2 3 4 5 6 7 8 9 10 ··· 21 下一页

2020年4月2日

python对象销毁顺序

摘要: 创建一个类SE: class SE(object): def __init__(self): print('init') def __del__(self): print('del') 创建两个SE实例,使用is判断: In [63]: SE() is SE() init init del del 阅读全文

posted @ 2020-04-02 12:37 不要挡着我晒太阳 阅读(421) 评论(0) 推荐(0) 编辑

2020年4月1日

python字符串驻留

摘要: In [1]: a = 'something' ...: b = 'some'+'thing' ...: id(a)==id(b) Out[1]: True 如果上面例子返回True,但是下面例子为什么是False: In [1]: a = '@zglg.com' In [2]: b = '@zgl 阅读全文

posted @ 2020-04-01 20:01 不要挡着我晒太阳 阅读(176) 评论(0) 推荐(0) 编辑

python绘图练习

摘要: 1 turtle绘制奥运五环图 import turtle as p def drawCircle(x,y,c='red'): p.pu()# 抬起画笔 p.goto(x,y) # 绘制圆的起始位置 p.pd()# 放下画笔 p.color(c)# 绘制c色圆环 p.circle(30,360) # 阅读全文

posted @ 2020-04-01 20:00 不要挡着我晒太阳 阅读(774) 评论(0) 推荐(0) 编辑

小练习2

摘要: 1#测试函数执行时间的装饰器示例 import time def timing_func(fn): def wrapper(): start=time.time() fn() #执行传入的fn参数 stop=time.time() return (stop-start) return wrapper 阅读全文

posted @ 2020-04-01 16:48 不要挡着我晒太阳 阅读(165) 评论(0) 推荐(0) 编辑

小练习

摘要: 1 寻找第n次出现位置 def search_n(s, c, n): size = 0 for i, x in enumerate(s): if x == c: size += 1 if size == n: return i return -1 print(search_n("fdasadfadf 阅读全文

posted @ 2020-04-01 15:44 不要挡着我晒太阳 阅读(172) 评论(0) 推荐(0) 编辑

4G 内存处理 10G 大小的文件

摘要: 4G 内存处理 10G 大小的文件,单机怎么做? 下面的讨论基于的假定:可以单独处理一行数据,行间数据相关性为零。 方法一: 仅使用 Python 内置模板,逐行读取到内存。 使用 yield,好处是解耦读取操作和处理操作: def python_read(filename): with open( 阅读全文

posted @ 2020-04-01 14:19 不要挡着我晒太阳 阅读(874) 评论(1) 推荐(0) 编辑

线程模块练习

摘要: 1.主线程 import threading t = threading.current_thread() print(t) # <_MainThread(MainThread, started 139908235814720)> print(t.getName()) # MainThread pr 阅读全文

posted @ 2020-04-01 14:07 不要挡着我晒太阳 阅读(107) 评论(0) 推荐(0) 编辑

时间模块练习

摘要: 1.年的日历图 import calendar from datetime import date mydate = date.today() year_calendar_str = calendar.calendar(2019) print(f"{mydate.year}年的日历图:{year_c 阅读全文

posted @ 2020-04-01 13:32 不要挡着我晒太阳 阅读(132) 评论(0) 推荐(0) 编辑

2020年3月31日

Python dictdiffer模块

摘要: Let’s start with an example on how to find the diff between two dictionaries using diff() method: from dictdiffer import diff, patch, swap, revert fir 阅读全文

posted @ 2020-03-31 19:24 不要挡着我晒太阳 阅读(1258) 评论(0) 推荐(0) 编辑

python文件操作练习

摘要: 1.获取后缀名 import os file_ext = os.path.splittext('./data/py/test.py') front,ext = file_ext print(front,ext) #'./data/py/test' #'.py' 2.创建文件夹 def mkdir(p 阅读全文

posted @ 2020-03-31 19:17 不要挡着我晒太阳 阅读(387) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 9 10 ··· 21 下一页

导航