![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python3
starry_lucky
这个作者很懒,什么都没留下…
展开
-
prettytable-以表格形式输出
prettytable创建表格形式1.以行的形式输入内容2.已列的方式输入内容创建表格形式1.以行的形式输入内容import prettytabletb = prettytable.PrettyTable() #`第一步:创建表头`tb.field_names = ['name','company_name','uesr_name','score']#第二步:插入数据for i in range(len(name_e)): tb.add_row([name_e[i],co原创 2021-03-06 14:25:44 · 266 阅读 · 0 评论 -
函数调用及执行
调用def run_get(url): res = requests.get(url).json() return res def q_list(res): q = jsonpath.jsonpath(res,'$.debugInfo[*].Info[*].q') for i in range(len(q)): q_list = [] ql = q[i].split('OR') qla = ql[-1].split(原创 2021-03-03 15:34:40 · 128 阅读 · 1 评论 -
抓取异常
try: # 执行体: a = 3 b = int(input('输入b:')) c = a + b print(c)except TypeError as e:#抓取异常,有异常时,抛出异常,不影响代码运行 print(e)finally:#这是一定会执行的部分,无论是否出错 c = 5 print(c)若想抓取多种异常,except (TypeError,ValueError) as e: print(e)...原创 2021-01-11 15:19:51 · 3009 阅读 · 0 评论 -
类详解
1.类的继承仅继承类,但不使用属性class Person(object): _city = 'beijing' def __init__(self, name): self._name = nameclass Student(Person): def __init__(self,score):#init会被标黄 self.score = scorea = Student(120)继承类的属性,并使用class Person(原创 2020-12-28 14:30:08 · 158 阅读 · 2 评论 -
关于文件路径
获取文件路径当前文件路径import osimport sys#获取当前文件路径On_path = os.path.realpath(__file__)print("当前文件路径:" + On_path) #获取当前文件的父路径parent_path = os.path.dirname(os.path.realpath(__file__))print("当前文件父目录:" + parent_path)#当前文件父目录的父目录garder = os.path.dirname(paren原创 2020-12-19 18:59:24 · 169 阅读 · 0 评论 -
文件操作
读取文件并转换成列表with open('1.txt','r',encoding='utf-8') as f: #按行读文件 # f_lines=f.readlines() # print(f_lines) # f_count = len(f_lines)#文件行数 # print(f_count) lines = [] for line in f.readlines(): a = line.split(' ')#str转换原创 2020-12-19 18:48:17 · 127 阅读 · 1 评论 -
类和对象
定义class student():#类 方法 函数 等a = student()#对象 初始化class student(): school = '北京大学' def __init__(self,name,a): id = self.id name = self.name self._a = a#隐藏属性 age = 18a = student('haha')1.如果需要取到该对原创 2020-12-19 17:39:18 · 98 阅读 · 1 评论 -
函数def
不限定传入的值**kwargs:必须以字典方式传入def a(name,**kwargs): print(f'name:{name},kwargs = {kwargs}') print(type(kwargs))a(name = 'zhang',p ='f')name:zhang,kwargs ={‘p’: ‘f’}<class ‘dict’>2.*args : 元组def a(name,*args): print(f'name:{name},a原创 2020-12-19 16:47:23 · 227 阅读 · 0 评论 -
字典dict
1.定义:a = {‘q’:1, ‘w’:2 ,‘e’:3}b = {2.取值a = {'q':1, 'w':2 ,'e':3}k = a.keys()v = a.values()t = a.items()print(k,'\t',v,'\t',t)print(list(k),'\t',list(v),'\t',list(t))结果:dict_keys([‘q’, ‘w’, ‘e’]) dict_values([1, 2, 3]) dict_items([(‘q’, 1),原创 2020-12-06 18:45:12 · 129 阅读 · 1 评论