随笔分类 -  Python

摘要:class Animal: x=123 def __init__(self,name): self._name=name self.__age=10 @property def name(self): return self._name def shout(self): print('Animal 阅读全文
posted @ 2020-10-03 13:14 ascertain 阅读(256) 评论(0) 推荐(0) 编辑
摘要:class Car: def __init__(self,brand,speed,color,price): self.b=brand self.s=speed self.c=color self.p=price def __repr__(self): return '''\ brand:%s sp 阅读全文
posted @ 2020-10-03 01:34 ascertain 阅读(131) 评论(0) 推荐(0) 编辑
摘要:import random class RandomGenerator: def __init__(self,count=10,minimum=1,maximum=100): self.count=count self.min=minimum self.max=maximum self.g=self 阅读全文
posted @ 2020-10-02 23:12 ascertain 阅读(122) 评论(0) 推荐(0) 编辑
摘要:在其他面向对象的高级语言中,都有重载的概念 重载: 同一个方法名,但是参数的数量和类型不一样,就是同一个方法的重载 Python没有重载 Python不需要重载 Python中,方法(函数)定义中,形参非常灵活,不需要指定类型(就是指定了,也只是一个说明,而非约束),参数个数也不固定(可变参数),一 阅读全文
posted @ 2020-10-02 21:56 ascertain 阅读(159) 评论(0) 推荐(0) 编辑
摘要:类中可以定义__del__方法,称为析构方法 作用: 销毁类的实例时调用,以释放占用的资源 由于python实现了垃圾回收机制,这个方法不确定何时执行,有必要时,使用del语句手动删除实例 class Person: def __init__(self,name,age=20): self.name 阅读全文
posted @ 2020-10-02 19:06 ascertain 阅读(173) 评论(0) 推荐(0) 编辑
摘要:property装饰器: 后面跟的函数名就是以后的属性,它即是getter,这个必须有,只读属性 setter装饰器: 于属性名同名,接收两个参数,第一个是self,第二个是将要赋值的值,将属性变为可写 deleter装饰器: 可以控制属性是否删除 property装饰器必须在前,setter,de 阅读全文
posted @ 2020-10-02 18:55 ascertain 阅读(815) 评论(0) 推荐(0) 编辑
摘要:lambda <args>:<expression> <expression>必须是单个表达式,不能是多个由;分割的表达式 使用exec函数 b=1 p=lambda v:exec("global b;b+=1;print(v+b)") print(p(1)) print(p(2)) 此种方式返回值 阅读全文
posted @ 2020-10-02 18:08 ascertain 阅读(3670) 评论(0) 推荐(0) 编辑
摘要:relevance.py from relevance1 import Mim from relevance2 import get p=Mim(22,33,44) print(p.get()) def monkeypath4Mim(): Mim.get=get if __name__ == '__ 阅读全文
posted @ 2020-10-02 13:10 ascertain 阅读(110) 评论(0) 推荐(0) 编辑
摘要:from pathlib import Path def openfile(path:str)->None: yield path def cix(path:str): p=Path(path) if p.exists(): if p.is_file(): yield from openfile(s 阅读全文
posted @ 2020-10-02 12:50 ascertain 阅读(193) 评论(0) 推荐(0) 编辑
摘要:from pathlib import Path import argparse,sys,datetime,stat,platform def showdir(path:str='.',all=False,detail=False,human=False,reverse=False): def co 阅读全文
posted @ 2020-10-02 11:25 ascertain 阅读(228) 评论(0) 推荐(0) 编辑
摘要:class Mse: @classmethod def __new__(cls,*args,**kwargs): pass @classmethod def class_method(cls): print('class={0.__name__} ({0})'.format(cls)) cls.HE 阅读全文
posted @ 2020-10-02 11:22 ascertain 阅读(133) 评论(0) 推荐(0) 编辑
摘要:import re,datetime,threading,queue from pathlib import Path from user_agents import parse from collections import defaultdict log='''10.1.1.95 - e800 阅读全文
posted @ 2020-10-01 19:00 ascertain 阅读(251) 评论(0) 推荐(0) 编辑
摘要:import datetime,random,time def source(): while True: yield {'value':random.randint(1,100),'datetime':datetime.datetime.now(datetime.timezone(datetime 阅读全文
posted @ 2020-10-01 18:45 ascertain 阅读(247) 评论(0) 推荐(0) 编辑
摘要:log='''10.1.1.95 - e800 [18/Mar/2005:12:21:42 +0800] \ "GET /stats/awstats.pl?config=e800 HTTP/1.1" 200 899 "http://10.1.1.1/pv/" \ "Mozilla/4.0 (comp 阅读全文
posted @ 2020-09-26 15:22 ascertain 阅读(139) 评论(0) 推荐(0) 编辑
摘要:from collections import defaultdict import re d=defaultdict(lambda :0) with open(r'e:/bb.txt',mode='rt+',encoding='utf8') as f: for line in f: for sub 阅读全文
posted @ 2020-09-25 23:48 ascertain 阅读(195) 评论(0) 推荐(0) 编辑
摘要:访问api查询数据,返回的json中有中文,利用json.tool格式化,发现中文以'\u4e09'这种Unicode编码显示 查找json的tool模块 find / -iname tool.py json.dump方法增加参数,即让json.tool模块不强行保证json的内容都转为ASCII编 阅读全文
posted @ 2020-09-24 16:25 ascertain 阅读(1118) 评论(0) 推荐(0) 编辑
摘要:os模块 import os print(os.name) Windows中os.name为nt Linux中os.name为posix sys模块 import sys print(sys.platform) Windows为win32 Linux为linux platform模块 import 阅读全文
posted @ 2020-09-20 16:56 ascertain 阅读(1688) 评论(0) 推荐(0) 编辑
摘要:pip install msgpack import msgpack,json js='{"person":[{"name":"zxc","age":18},{"name":"vbn","age":88},{"name":"uio","age":99}],"total":3}' d=json.loa 阅读全文
posted @ 2020-09-19 22:53 ascertain 阅读(228) 评论(0) 推荐(0) 编辑
摘要:import json from pathlib import Path pp={'a':123,'b':['bam',{'c':789}],'d':True,'m':False,'v':None} # print(p) # print(json.dumps(p)) # b=json.dumps(p 阅读全文
posted @ 2020-09-19 21:58 ascertain 阅读(86) 评论(0) 推荐(0) 编辑
摘要:s="""\ 1,tom,20, 2,jerry,30, 3,,, """ with open('c:/vbn.csv',mode='wt+') as f: # for line in s.splitlines(keepends=True): # print(line) # f.write(line 阅读全文
posted @ 2020-09-19 20:51 ascertain 阅读(91) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示