05 2020 档案

摘要:import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 设置如上参数即可 2020 阅读全文
posted @ 2020-05-31 20:28 Hany47315 编辑
摘要:import pandas as pd import numpy as np data = pd.read_excel('学生成绩表.csv',columns = ['学号','姓名','高数','英语','计算机']) sum_score = [ ] for i in range(len(data 阅读全文
posted @ 2020-05-31 18:10 Hany47315 编辑
摘要:dll 版本不对 dll 可能是 32 位和 64 位的 ,安装的可能不对 下载 DirectX_DLL修复工具v3.5增强版 进行修复 VC++ 安装第三方库报红问题 使用 VS 2017 或者 VS2019 版本 ,不要使用 VS 2015 2020-05-30 阅读全文
posted @ 2020-05-30 16:35 Hany47315 编辑
摘要:''' 【问题描述】定义一个函数判断是否为素数isPrime(), 主程序通过调用函数输出2-30之间所有的素数。 素数:一个大于1的自然数,除了1和它本身外,不能被其他自然数整除。 【输入形式】无【输出形式】2~30之间所有的索数(逗号分隔) 【样例输入】【样例输出】2,3,5,7,11,13,1 阅读全文
posted @ 2020-05-30 12:33 Hany47315 编辑
摘要:''' 16. 编写程序计算学生的平均分。 【输入形式】输入的第一行表示学生人数n; 标准输入的第2至n+1行表示学生成绩。 【输出形式】输出的一行表示平均分(保留两位小数)。 若输入的数据不合法(学生人数不是大于0的整数, 或学生成绩小于0或大于100),输出“illegal input”。 '' 阅读全文
posted @ 2020-05-30 12:32 Hany47315 编辑
摘要:''' 11. 编写程序,判断一个数是不是素数,是则输出“Yes”,不是输出“No”.(while循环) ''' num = int(input()) i = 2 flag = True while i < num: if num % i ==0: flag = False i += 1 if fl 阅读全文
posted @ 2020-05-30 12:31 Hany47315 编辑
摘要:''' 1. 编写程序,功能是把输入的字符串的大写字母变成小写字母, 小写字母变成大写字母,非字母的字符不作变换。输出变换后的结果 ''' string = input() s = '' for str in string: if 'a' <= str <= 'z': s += str.upper( 阅读全文
posted @ 2020-05-30 12:30 Hany47315 编辑
摘要:''' 6. 一元二次方程:ax2+bx+c=0 (a ╪ 0) 【输入形式】输入a、b和c的值(有理数) 【输出形式】输出x的两个值,或者No(即没有有理数的解) ''' import math a = int(input()) b = int(input()) c = int(input()) 阅读全文
posted @ 2020-05-30 12:29 Hany47315 编辑
摘要:tom 85 90 jerry 95 80 lucy 80 90 rose 88 90 jay 76 75 summer 87 85 horry 84 80 dic = {} with open('score.txt','r') as f: lines = f.readlines() f.close 阅读全文
posted @ 2020-05-30 08:59 Hany47315 编辑
摘要:import pandas as pd def get_data(): q1 = [] q2 = [] p1 = input("list 1:") p2 = input("list 2:") q1=p1.split(',') q2=p2.split(',') for i,j in zip(range 阅读全文
posted @ 2020-05-29 22:26 Hany47315 编辑
摘要:def dollar(n): global story_money money = [] for i in range(10): if 2**(i+1) > story_money-sum(money): money.append(story_money-2**i+1) break money.ap 阅读全文
posted @ 2020-05-29 19:58 Hany47315 编辑
摘要:将 NaN 替换成某一数值 使用 fillna dataframe.fillna(value = 'xxx',inplace=True) 删除某一个值 使用 drop dataframe.drop(10,inplace=True) 交换两行的值 if m != n: temp = np.copy(d 阅读全文
posted @ 2020-05-29 18:26 Hany47315 编辑
摘要:file = open('abc.txt','r',encoding='utf-8') file = open('abc.txt','w',encoding='utf-8') 'w' 写入模式 会清空掉文件,然后再写入 不想完全覆盖掉原文件的话,使用'a' 关键字with,with open(xxx 阅读全文
posted @ 2020-05-29 12:06 Hany47315 编辑
摘要:import random ganran = float(input("请输入感染概率")) is_person_ganran = False # 人是否感染了 person_ganran = random.randint(0,100) if person_ganran /100 < ganran: 阅读全文
posted @ 2020-05-29 10:28 Hany47315 编辑
摘要:python 版本 3.6 不要使用 3.7 和 3.8 否则导致安装失败 tensorflow 使用 1.12.0 keras 使用 2.2.4 版本 pip install 包名 -i http://pypi.douban.com/simple/ --trusted-host pypi.doub 阅读全文
posted @ 2020-05-28 22:48 Hany47315 编辑
摘要:当获取到的数据不存在时,可以通过设置一个 len( data ) 设置一个长度 ,过滤掉 不到长度的数据 设置一个布尔类型的全局变量 当访问到时 设置为 True 如果没有访问到,则设置为 False根据全局变量的值,判断是否继续进行访问 2020-05-28 阅读全文
posted @ 2020-05-28 21:05 Hany47315 编辑
摘要:os.chdir(r"C:\Users\47311\Desktop\code\") #修改为自己文件路径 data = pd.read_excel(r"公司公告2020.xlsx")[:-1] #读入数据,并删除最后一行(最后一行为空值) 读取的数据在 chdir 之下 存在多个数据时,使用字符串类 阅读全文
posted @ 2020-05-28 13:18 Hany47315 编辑
摘要:在 templates 中创建对应文件名的 html 文件 (404.html) 注: 开发者服务器发生变更是因为 python 代码发生变化 如果 html 文件发生变化,服务器不会进行重启 需要自己手动修改 注意就近原则,如果有重复名字,先用最近的 阅读全文
posted @ 2020-05-28 12:40 Hany47315 编辑
摘要:''' 1. 编写程序实现:计算并输出标准输入的三个数中绝对值最小的数。 ''' #计算并输出标准输入的三个数中绝对值最小的数。 import math num1 = int(input()) num2 = int(input()) num3 = int(input()) num_list = (n 阅读全文
posted @ 2020-05-28 10:15 Hany47315 编辑
摘要:score.txt 文件内容 李彦宏 男 英语 80 李彦宏 男 电子技术基础 75 李彦宏 男 Python程序设计 88 马云 男 英语 62 马云 男 电子技术基础 63 马云 男 Python程序设计 68 黄蓉 女 英语 90 黄蓉 女 电子技术基础 80 黄蓉 女 Python程序设计 阅读全文
posted @ 2020-05-28 10:13 Hany47315 编辑
摘要:一闪而过可能是程序出错,导致的 .py 文件导入的文件,使用相对路径 在导包成 exe 文件时 将使用到的文件放入到 同一文件夹内 即可运行 另外,程序一闪而过 可以考虑使用 time.sleep(30) 方法 2020-05-27 阅读全文
posted @ 2020-05-27 22:05 Hany47315 编辑
摘要:import re pattern = '\d+?\.\d+' s = "[Decimal('90.900000')]" s2 = "[Decimal('75.900000'),Decimal('57.280000')]" [print(i,end = " ") for i in re.findal 阅读全文
posted @ 2020-05-27 12:16 Hany47315 编辑
摘要:import random def no_change(times): glass_ball = 0 diamond = 0 times2=times while times>0: drawers={'drawer1': False, 'drawer2': False, 'drawer3': Fal 阅读全文
posted @ 2020-05-27 11:03 Hany47315 编辑
摘要:import numpy as np import pandas as pd import matplotlib.pyplot as plt cqlq=pd.read_csv("cqlq.txt",sep="\s+",encoding="gbk") dxnt=pd.read_csv("dxnt.tx 阅读全文
posted @ 2020-05-27 10:58 Hany47315 编辑
摘要:def predict(train_samples,X): #描述属性分别用数字代替 #年龄: <=30:0, 30~40:1, <40:2 #收入:‘低’:0,'中':1,'高':2 #是否学生:‘是’:1,'否':1 #信誉: '中':0,'优':1 #购买属性用数字代替 #购买电脑 :‘是’: 阅读全文
posted @ 2020-05-27 10:56 Hany47315 编辑
摘要:import sqlite3 conn = sqlite3.connect('studentsdb.db') # 连接数据库 cursor = conn.cursor( ) # 创建数据表 def createDatabase(): '''创建一个数据表''' sql = 'create table 阅读全文
posted @ 2020-05-27 10:54 Hany47315 编辑
摘要:import pandas as pd import numpy as np import matplotlib.pyplot as plt cqlq = pd.read_excel("cqlq.xls",sep='\s+') dxnt = pd.read_excel("dxnt.xls",sep= 阅读全文
posted @ 2020-05-27 10:53 Hany47315 编辑
摘要:c = [[0, 0, 0, 0], [0, 2, 4, 4], [0, 4, 1, 2], [0, 4, 2, 2]] o = [0, 8, 14, 10] d = [0, 8, 14, 10] am = [0, 1, 1, 1] ampl1 = [0, 0, 0, 0] bm = [0, 0, 阅读全文
posted @ 2020-05-26 20:54 Hany47315 编辑
摘要:import numpy as np import pandas as pd import matplotlib.pyplot as plt cqlq=pd.read_csv("cqlq.txt",sep="\s+",encoding="gbk") dxnt=pd.read_csv("dxnt.tx 阅读全文
posted @ 2020-05-26 20:52 Hany47315 编辑
摘要:inf = float('inf') 此时的 inf 就是无穷了 2020-05-26 阅读全文
posted @ 2020-05-26 20:49 Hany47315 编辑
摘要:import jieba strings = '我工作在安徽的安徽师范大学,这个大学很美丽,在芜湖' # print(dir(jieba)) dic_strings = {} lst_strings = jieba.lcut(strings) for ci in lst_strings: # 对得到 阅读全文
posted @ 2020-05-25 17:00 Hany47315 编辑
摘要:for i in range(1000,2201): if i % 7 == 0 and i % 5 != 0: print(i,end = " ") def func(num): if num == 0: return 1 return num * func(num - 1) print(func 阅读全文
posted @ 2020-05-25 16:26 Hany47315 编辑
摘要:from turtle import * def go_to(x, y): up() goto(x, y) down() def head(x, y, r): go_to(x, y) speed(1) circle(r) leg(x, y) def leg(x, y): right(90) forw 阅读全文
posted @ 2020-05-24 21:32 Hany47315 编辑
摘要:''' 开始,你可以随意选择一个抽屉,在开启它之前, 主持人会开启另外一个抽屉,露出抽屉里的玻璃球。 这时,主持人会给你一次更换自己选择的机会。 请自己认真分析一下“不换选择能有更高的几率获得钻石, 还是换选择能有更高的几率获得钻石?或几率没有发生变化?”写出你分析的思路和结果。 设法编写pytho 阅读全文
posted @ 2020-05-24 20:00 Hany47315 编辑
摘要:lst = ['中雨','雷阵雨','中到大雨','阴','多云','晴','中雨'] dic = {} for i in lst: if i not in dic: dic[i] = lst.count(i) print(dic) 2020-05-24 阅读全文
posted @ 2020-05-24 17:09 Hany47315 编辑
摘要:3D图形 导包 import numpy as np import matplotlib.pyplot as plt #3d图形必须的 from mpl_toolkits.mplot3d.axes3d import Axes3D %matplotlib inline 生成数据 #系数,由X,Y生成Z 阅读全文
posted @ 2020-05-24 14:55 Hany47315 编辑
摘要:四图 直方图 【直方图的参数只有一个x!!!不像条形图需要传入x,y】 hist()的参数 bins 可以是一个bin数量的整数值,也可以是表示bin的一个序列。默认值为10 normed 如果值为True,直方图的值将进行归一化处理,形成概率密度,默认值为False color 指定直方图的颜色。 阅读全文
posted @ 2020-05-24 14:29 Hany47315 编辑
摘要:设置plot的风格和样式 点和线的样式 颜色 参数color或c 五种定义颜色值的方式 别名 color='r' 合法的HTML颜色名 color = 'red' HTML十六进制字符串 color = '#eeefff' 归一化到[0, 1]的RGB元组 color = (0.3, 0.3, 0. 阅读全文
posted @ 2020-05-24 14:20 Hany47315 编辑
摘要:灰度化处理就是将一幅色彩图像转化为灰度图像的过程。彩色图像分为R,G,B三个分量,分别显示出红绿蓝等各种颜色,灰度化就是使彩色的R,G,B分量相等的过程。灰度值大的像素点比较亮(像素值最大为255,为白色),反之比较暗(像素最下为0,为黑色)。 图像灰度化的算法主要有以下3种: data2 = da 阅读全文
posted @ 2020-05-24 14:11 Hany47315 编辑
摘要:fruit = [] def menu(): print( ''' ********************水果超市******************** (面向对象,面向过程) 1. 查询全部水果 2. 查询指定名称的水果 3. 增加水果(增加到数据库) 4. 修改水果数量或者价格 5. 删除水 阅读全文
posted @ 2020-05-24 12:27 Hany47315 编辑
摘要:def numRoot(num): '''定义数根函数''' if len(num) == 1: return int(num) else: nums = [] for i in range(len(num)): # 对字符串进行遍历 nums.append(int(num[i])) if sum( 阅读全文
posted @ 2020-05-23 18:06 Hany47315 编辑
摘要:'''定义函数,给定一个列表作为函数参数,将列表中的非数字字符去除。''' class list: def __init__(self,alist): self.alist=alist def remove_str(self): a="" for i in self.alist: b=str(i) 阅读全文
posted @ 2020-05-23 16:39 Hany47315 编辑
摘要:import re # 导入正则表达式模块 import os # 导入操作系统模块 filename = "students.txt" # 定义保存学生信息的文件名 def menu(): # 输出菜单 print(''' ╔———————学生信息管理系统————————╗ │ │ │ 功能菜单 阅读全文
posted @ 2020-05-23 08:50 Hany47315 编辑
摘要:import math def f(n): if isinstance(n,int): for i in range(round(math.sqrt(n))): for j in range(round(math.sqrt(n))): for k in range(round(math.sqrt(n 阅读全文
posted @ 2020-05-22 22:49 Hany47315 编辑
摘要:for i in range(1000,10000): t=str(i) if pow(eval(t[0]),4)+pow(eval(t[1]),4)+pow(eval(t[2]),4)+pow(eval(t[3]),4) == i: print(i) 2020-05-22 阅读全文
posted @ 2020-05-22 22:09 Hany47315 编辑
摘要:''' 每一个学生的总分,每个课程的平均分,最高分,最低分 ''' # 创建学生列表 stuLst = [] # 创建学生信息 stu1 = {'学号':'1001','姓名':'小明','高数':95,'英语':88,'计算机':80} stu2 = {'学号':'1002','姓名':'小李', 阅读全文
posted @ 2020-05-22 21:38 Hany47315 编辑
摘要:Django暂时停止更新,先把学校实验报告弄完 ''' 计算 1.输入半径,输出面积和周长 2.输入面积,输出半径及周长 3.输入周长,输出半径及面积 ''' '''1.输入半径,输出面积和周长''' from math import pi '''定义半径''' r = int(input("请输入 阅读全文
posted @ 2020-05-21 21:01 Hany47315 编辑
摘要:from django.shortcuts import render,redirect from django.http import HttpResponse,JsonResponse from datetime import datetime,timedelta # Create your v 阅读全文
posted @ 2020-05-20 11:00 Hany47315 编辑
摘要:from django.db import models # Create your models here. class BookInfoManager(models.Manager): '''图书模型管理器类''' # 1.改变原有查询的结果集 def all(self): # 1.调用父类的a 阅读全文
posted @ 2020-05-19 22:29 Hany47315 编辑
摘要:保存日期 def create(request): '''新增一本图书''' # 1.创建BookInfo对象 b = BookInfo() b.btitle = '流星蝴蝶剑' b.bpub_date = date(1990,1,1) # 2.保存进数据库 b.save() # 3.返回应答,让浏 阅读全文
posted @ 2020-05-19 22:28 Hany47315 编辑
摘要:创建管理员 python manage.py createsuperuser 数据库属性命名限制 1.不能是python的保留关键字 2.不允许使用连续的下划线,这是由django的查询方式决定的 3.定义属性时需要指定字段类型,通过字段类型的参数指定选项 语法如下: 属性名=models.字段类型 阅读全文
posted @ 2020-05-18 16:58 Hany47315 编辑
摘要:# 输入年月日 year = int(input('year:')) month = int(input('month:')) day = int(input('day:')) # 将正常情况下,每一个月的累计天数放入到元组中进行保存 months = (0,31,59,90,120,151,181 阅读全文
posted @ 2020-05-18 14:23 Hany47315 编辑
摘要:问题简述:假设一支皮球从100米高度自由落下。条件,每次落地后反跳回原高度的一半后,再落下。 要求:算出这支皮球,在它在第10次落地时,共经过多少米?第10次反弹多高? 解题思路 总共初始高度 100 米 高度 每次弹起一半距离 每一次弹起 上升的高度和下降的高度 是一次的距离 每一次弹起,高度都会 阅读全文
posted @ 2020-05-18 14:13 Hany47315 编辑
摘要:把一个合数分解成若干个质因数的乘积的形式,即求质因数的过程叫做分解质因数。 Python练习题问题如下: 要求:将一个正整数分解质因数;例如您输入90,分解打印90=2*3*3*5。 Python解题思路分析: 这道题需要分三部分来分解,具体分解说明如下。 1、首先当这个质数恰等于n的情况下,则说明 阅读全文
posted @ 2020-05-18 14:05 Hany47315 编辑
摘要:urls 中 进行注册 url(r'grades',views.grades) views 中编写函数 def grades(request): grades_list = Grade.objects.all() # 使用 locals 获取本地变量 return render(request,'g 阅读全文
posted @ 2020-05-18 11:18 Hany47315 编辑
摘要:在 settings 中添加 INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.con 阅读全文
posted @ 2020-05-17 11:40 Hany47315 编辑
摘要:在 static 静态文件夹下创建 css 文件夹 home.css 此时 home.css 路径是 'static/css/home.css' 在 对应的 home.html 文件中添加 css 样式 {% block ext_css %} {# <link rel="stylesheet" hr 阅读全文
posted @ 2020-05-16 12:17 Hany47315 编辑
摘要:在 templates 文件夹下创建 基类 base.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>{{ title }}</title> </head> <body> {% block head 阅读全文
posted @ 2020-05-16 09:32 Hany47315 编辑
摘要:谨慎使用 自动渲染语法 {{code|safe}} urls.py 中添加对应的函数 url(r'getcode',views.getcode) 在 views.py 中添加 def getcode(request): code = "<h2> HTML 转义示例 </h2>" context_co 阅读全文
posted @ 2020-05-16 07:37 Hany47315 编辑
摘要:在 urls 中注册 url(r'getstr',views.getstr) 在 views.py 中添加函数 def getstr(request): string = 'abc' string_2 = 'ABC' context_str = { 'string':string, 'string_ 阅读全文
posted @ 2020-05-14 20:38 Hany47315 编辑
摘要:{% ifequal 数值 数值 %} <body> {# 判断是否相等 #} num 当前的值 {{ num }}<br/> {% ifequal num 5 %} {# 判断 num 是否等于 5#} num 的值是 5 {% endifequal %} </body> {% ifnotequa 阅读全文
posted @ 2020-05-14 20:13 Hany47315 编辑
摘要:urls 中 url(r'getnum',views.getnum) views.py 中添加对应的函数 def getnum(request): num = 5 context_num = { 'num':num } return render(request,'num_ys.html',cont 阅读全文
posted @ 2020-05-14 19:41 Hany47315 编辑
摘要:if else 格式 {% if 条件 %} <标签>语句</标签> {%else%} <标签>语句</标签> {%endif} 标签都可以添加样式 {% for stu in students %} {% if forloop.first %} <li style="color: chartreu 阅读全文
posted @ 2020-05-14 12:20 Hany47315 编辑
摘要:当查找的数据不存在,返回为 空时 在 html 中使用 {%empty%} 语句 进行显示 def getstudents(request): students = Student.objects.all().filter(s_name = 'qwer') # 指定一个不存在的值, # studen 阅读全文
posted @ 2020-05-14 11:59 Hany47315 编辑
摘要:创建 app6 在项目的 settings 中进行注册 INSTALLED_APPS 里面添加 'app6.apps.App6Config' 在 app6 的models.py 中创建数据表 class Student(models.Model): s_name = models.CharField 阅读全文
posted @ 2020-05-13 16:21 Hany47315 编辑
摘要:视频链接 https://www.bilibili.com/video/BV1rx411X717?p=21 千锋教育出品的 Django 课程 2020-05-13 阅读全文
posted @ 2020-05-13 13:23 Hany47315 编辑
摘要:如果在 创建数据表时,使用了 objects = models.Model() 使隐形属性变为了 显性属性 则 必须要自己定义一个 继承了 models.Model 类的类,实现 管理功能 如果一个属性一直都需要使用 比如 is_delete 属性,判断 这条数据是否删除 is_delete 为 T 阅读全文
posted @ 2020-05-13 11:07 Hany47315 编辑
摘要:邻接矩阵 class Vertex: def __init__(self, node): self.id = node # Mark all nodes unvisited self.visited = False def addNeighbor(self, neighbor, G): G.addE 阅读全文
posted @ 2020-05-11 18:55 Hany47315 编辑
摘要:def create(q,graph,N): #compute Probability Matrix L = [[(1-q)/N]*N for i in range(N)] for node,edges in enumerate(graph): num_edge = len(edges) for e 阅读全文
posted @ 2020-05-11 18:47 Hany47315 编辑
摘要:F 对象: 可以使用模型的 A 属性和 B 属性进行比较 写法: 需要的数据对象 = 数据表(类名).objects.filter(列名__条件=F('列名2')) 需求: 查看男生数量比女生少 的公司名称 companies = Company.objects.filter(c_boy_num__ 阅读全文
posted @ 2020-05-11 17:17 Hany47315 编辑
摘要:使用方法: 类名.objects.aggregate(聚合函数名('表的列名')) 聚合函数名: Avg 平均值 Count数量 Max 最大 Min 最小 Sum 求和 示例: Student.objects.aggregate(Max('sage')) 创建消费者数据表 Customer cla 阅读全文
posted @ 2020-05-11 14:37 Hany47315 编辑
摘要:在 urls.py 中先导入getgrades from django.conf.urls import url from app5 import views urlpatterns = [ url(r'getuser/',views.get_user), url(r'getusers/',view 阅读全文
posted @ 2020-05-11 14:04 Hany47315 编辑
摘要:在 app5.models.py 中添加一个 Order 表 class Order(models.Model): o_num = models.CharField(max_length= 16 ,unique=True) # 创建一个订单号,设置为 唯一 o_time = models.DateT 阅读全文
posted @ 2020-05-11 12:10 Hany47315 编辑
摘要:在创建订单的时候会创建一个对应的日期 查询数据库表的时候,查询年的话可以正常实现 但是如果单独查询某一个月的话,可能会出错 在 Django 中月份可能会使用 Django 中定义的时区 将 项目 settings.py 中的 USE_TZ = True 改为 False 2020-05-11 阅读全文
posted @ 2020-05-11 11:36 Hany47315 编辑
摘要:def f(self,x): y = x + 3 return y class Add: # 创建一个 Add 类 def add(self,a): return a + 4 f1 = f # 让 f1 等于外面定义的函数 f n = Add() # 创建实例化对象 print(n.add(4)) 阅读全文
posted @ 2020-05-11 10:14 Hany47315 编辑
摘要:在 views.py 中添加 获取函数 注:此时获取的是全部用户的信息 def get_users(request): users = User.objects.all() context = { 'users':users } return render(request,'user_list.ht 阅读全文
posted @ 2020-05-11 09:58 Hany47315 编辑
摘要:在 models.py 中设置数据库表的信息 from django.db import models # Create your models here. class User(models.Model): u_name = models.CharField(max_length=16,uniqu 阅读全文
posted @ 2020-05-10 19:50 Hany47315 编辑
摘要:查看MySQL支持的存储引擎 查看当前所有数据库 创建一个数据库 选择当前操作的数据库 删除数据库 查看数据库表 创建一个数据库表 显示表的结构 查看创建表的创建语句 向表中加入记录 删除记录 更新记录 删除表 2020-05-10 阅读全文
posted @ 2020-05-10 11:06 Hany47315 编辑
摘要:Person.objects.all() 获取全部数据 def get_persons(request): persons = Person.objects.all() # 获取全部数据 context = { 'persons':persons # 传递到前端代码中 } return render 阅读全文
posted @ 2020-05-09 18:42 Hany47315 编辑
摘要:在 views.py 中添加函数 向数据库中添加数据 def add_persons(request): for i in range(15): person = Person() flag = random.randrange(100) person.p_name = "Hany_ %d"%(i) 阅读全文
posted @ 2020-05-09 17:52 Hany47315 编辑
摘要:在 models.py 中添加 from django.db import models # Create your models here. class Person(models.Model): # 伪装成 models p_name = models.CharField(max_length= 阅读全文
posted @ 2020-05-09 14:41 Hany47315 编辑
摘要:单例模式的懒汉式 在导入模块的时候,可能会无意中创建一个对象,但当时根本用不到 懒汉式实例化能够确保在实际需要时才创建对象 懒汉式实例化是一种节约资源并仅在需要时才创建它们的方式 class Singleton: _instance = None def __init__(self): if not 阅读全文
posted @ 2020-05-09 13:09 Hany47315 编辑
摘要:设计模式分类: 结构型 行为型 创建型 单例模式属于创建型设计模式 单例模式主要使用在 日志记录 ->将多项服务的日志信息按照顺序保存到一个特定日志文件 数据库操作 -> 使用一个数据库对象进行操作,保证数据的一致性 打印机后台处理程序 以及其他程序 该程序运行过程中 只能生成一个实例 避免对同一资 阅读全文
posted @ 2020-05-09 12:15 Hany47315 编辑
摘要:以下图示为 学习过程中,在千锋教育视频上截图的 视频链接: https://www.bilibili.com/video/BV1rx411X717?p=11 2020-05-09 阅读全文
posted @ 2020-05-09 11:56 Hany47315 编辑
摘要:在创建好的 app3 目录下的 models.py 中 创建对 数据表(学生和班级)的描述 分析: 学生和班级是一对多的关系 班级表的设计 class Grade(models.Model): # 设置班级名字 g_name = models.CharField(max_length=32) 学生表 阅读全文
posted @ 2020-05-08 18:16 Hany47315 编辑
摘要:在根目录下创建一个 app3 app3 是新 app 的名字 创建一个 urls.py 在 urls.py 中添加 urlpatterns 列表 容纳需要显示在页面上的函数 from django.conf.urls import url from app3 import views urlpatt 阅读全文
posted @ 2020-05-08 11:27 Hany47315 编辑
摘要:示例1 from time import ctime,sleep #导包就不需要使用包名.函数了 def timefun(func): def wrappedfunc(): print("%s called at %s"%(func.__name__,ctime())) func()#内部函数需要使 阅读全文
posted @ 2020-05-08 10:00 Hany47315 编辑
摘要:def foo(): print("foo") print(foo) # 输出foo的地址 foo()#对foo函数的调用 def foo(): print("foo2") foo = lambda x : x+1 # 使用foo对象接收函数 print(foo(2)) def w(func): d 阅读全文
posted @ 2020-05-08 09:44 Hany47315 编辑
摘要:""" 输入 graph 输入的图 src 原点 返回 dis 记录源点到其他点的最短距离 path 路径 """ import json def dijkstra(graph, src): if graph == None: return None # 定点集合 nodes = [i for i 阅读全文
posted @ 2020-05-08 09:42 Hany47315 编辑
摘要:#coding=utf-8 class UpperAttrMetaClass(type): # __new__ 是在__init__之前被调用的特殊方法 # __new__是用来创建对象并返回之的方法 # 而__init__只是用来将传入的参数初始化给对象 # __new__能够控制对象的创建 # 阅读全文
posted @ 2020-05-08 09:40 Hany47315 编辑
摘要:def test(number): #在函数内部再定义一个函数,并且这个函数用到了外边函数的变量,那么将这个函数以及用到的一些变量称之为闭包 def test_in(number_in): print("in test_in 函数, number_in is %d"%number_in) retur 阅读全文
posted @ 2020-05-08 09:39 Hany47315 编辑
摘要:#方法一 import random range_lst = [random.randint(0,100) for i in range(100)] # 创建一个包含有 100 个数据的随机数 range_set = set(range_lst) # 创建集合,不包含重复元素 for num in 阅读全文
posted @ 2020-05-08 09:38 Hany47315 编辑
摘要:def func_class(string): if string == 'class_one': class class_one: pass return class_one else: class class_two: pass return class_two MyClass = func_c 阅读全文
posted @ 2020-05-08 00:59 Hany47315 编辑
摘要:class ObjectCreator(object): pass print(ObjectCreator) # 打印 ObjectCreator.name = 'XiaoLiu' # 对ObjectCreator类增加属性,以后使用ObjectCreator类时,都具有name属性 g = lam 阅读全文
posted @ 2020-05-08 00:58 Hany47315 编辑
摘要:dic = {'a':123,'b':456} print("{0}:{1}".format(*dic)) a:b 2020-05-08 阅读全文
posted @ 2020-05-08 00:57 Hany47315 编辑
摘要:a = [1,2,3,4] print(id(a)) b = a print(id(b)) # 地址相同 a.append('a') print(a) print(b)#b和a的值一致,a改变,b就跟着改变 ''' 2342960103104 2342960103104 [1, 2, 3, 4, ' 阅读全文
posted @ 2020-05-08 00:55 Hany47315 编辑
摘要:查看一个对象的引用计数 a = "Hello World " import sys print("a的引用计数为:",sys.getrefcount(a)) '''a的引用计数为: 4''' a = 23 b = a def func(a): print(a) lst = [a] 2020-05-0 阅读全文
posted @ 2020-05-08 00:54 Hany47315 编辑
摘要:class Person(object): def __init__(self,name = None,age = None): self.name = name#类中拥有的属性 self.age = age def eat (self): print("%s在吃东西"%(self.name)) p 阅读全文
posted @ 2020-05-08 00:53 Hany47315 编辑
摘要:查看complex的__class__属性 a = 5+2j print(a.__class__) print(a.__class__.__class__) ''' <class 'complex'> <class 'type'> ''' 查看int的__class__属性 a = 123 prin 阅读全文
posted @ 2020-05-08 00:51 Hany47315 编辑
摘要:a = "abc" b = a[:] print(a,b)#值相同 print(id(a),id(b))#地址相同(字符串是不可变类型) d = dict(name = "Xiaoming",age = 22) d_copy = d.copy() print( d ,id(d)) print(d_c 阅读全文
posted @ 2020-05-08 00:50 Hany47315 编辑
摘要:class Person(object): def __init__(self,name,age,taste): self.name = name self._age = age self.__taste = taste def showPerson(self): print(self.name) 阅读全文
posted @ 2020-05-08 00:48 Hany47315 编辑
摘要:class MyList(object): """自定义的一个可迭代对象""" def __init__(self): self.items = [] def add(self, val): self.items.append(val) def __iter__(self): myiterator 阅读全文
posted @ 2020-05-08 00:47 Hany47315 编辑
摘要:import time # yield配合next使用 def work1(): while True: print(" work1 ") yield time.sleep(0.3) def work2(): while True: print(" work2 ") yield time.sleep 阅读全文
posted @ 2020-05-08 00:46 Hany47315 编辑
摘要:#大整数对象池 b = 1500 a = 1254 print(id(a)) print(id(b)) b = a print(id(b)) a1 = "Hello 垃圾机制" a2 = "Hello 垃圾机制" print(id(a1),id(a2)) del a1 del a2 a3 = "He 阅读全文
posted @ 2020-05-08 00:45 Hany47315 编辑
摘要:''' 创建mutex = threading.Lock( ) 锁定mutex.acquire([blocking]) 释放mutex.release( ) 创建->锁定->释放 ''' from threading import Thread,Lock from time import sleep 阅读全文
posted @ 2020-05-08 00:44 Hany47315 编辑
摘要:class Person(object): def __init__(self,name = None,age = None): self.name = name self.age = age def __str__(self): return "%s 的年龄为 %d 岁 %s性"%(self.na 阅读全文
posted @ 2020-05-08 00:43 Hany47315 编辑
摘要:G = (x*2 for x in range(4)) print(G) print(G.__next__()) print(next(G))#两种方法等价 # G每一次读取,指针都会下移 for x in G: print(x,end = " ") 2020-05-08 阅读全文
posted @ 2020-05-08 00:42 Hany47315 编辑
摘要:class FibIterator(object): """斐波那契数列迭代器""" def __init__(self, n): """ :param n: int, 指明生成数列的前n个数 """ self.n = n # current用来保存当前生成到数列中的第几个数了 self.curre 阅读全文
posted @ 2020-05-08 00:40 Hany47315 编辑
摘要:类方法 class ObjectCreator(object): pass @classmethod def testClass(cls): cls.temp = 666 print(cls.temp) test = type("Test",(ObjectCreator,),{'testClass' 阅读全文
posted @ 2020-05-08 00:39 Hany47315 编辑
摘要:import types class ppp: pass p = ppp()#p为ppp类实例对象 def run(self): print("run函数") r = types.MethodType(run,p) #函数名,类实例对象 r() ''' run函数 ''' 2020-05-08 阅读全文
posted @ 2020-05-08 00:38 Hany47315 编辑
摘要:class Days(object): def __init__(self): self.__days = 0 @property def days(self):#获取函数,名字是days days 是get方法 return self.__days @days.setter #get方法的set方 阅读全文
posted @ 2020-05-08 00:36 Hany47315 编辑
摘要:import pdb a = 'aaa' pdb.set_trace( ) b = 'bbb' c = 'ccc' final = a+b+c print(final) import pdb a = 'aaa' pdb.set_trace( ) b = 'bbb' c = 'ccc' pdb.set 阅读全文
posted @ 2020-05-08 00:35 Hany47315 编辑
摘要:def counter(start = 0): def incr(): nonlocal start #分别保存每一个变量的临时值、类似yield start += 1 return start return incr c1 = counter(5) print(c1()) c2 = counter 阅读全文
posted @ 2020-05-08 00:34 Hany47315 编辑
摘要:''' timeit库Timer函数 ''' from timeit import Timer def test1(): l = list(range(1000)) def test2(): l = [] for i in range(1000): l.append(i) def test3(): 阅读全文
posted @ 2020-05-08 00:33 Hany47315 编辑
摘要:def upper_attr(future_class_name, future_class_parents, future_class_attr): #遍历属性字典,把不是__开头的属性名字变为大写 newAttr = {} for name,value in future_class_attr. 阅读全文
posted @ 2020-05-08 00:32 Hany47315 编辑
摘要:from collections import Iterable print(isinstance([],Iterable)) print(isinstance( {}, Iterable)) print(isinstance( (), Iterable)) print(isinstance( 'a 阅读全文
posted @ 2020-05-08 00:30 Hany47315 编辑
摘要:使用__slots__时,子类不受影响 class Person(object): __slots__ = ("name","age") def __str__(self): return "姓名:%s,年龄:%d"%(self.name,self.age) p = Person() class m 阅读全文
posted @ 2020-05-08 00:29 Hany47315 编辑
摘要:# import hashlib # mima = hashlib.md5()#创建hash对象,md5是信息摘要算法,生成128位密文 # print(mima) # # mima.update('参数')使用参数更新哈希对象 # print(mima.hexdigest())#返回16进制的数字 阅读全文
posted @ 2020-05-08 00:27 Hany47315 编辑
摘要:""" 1、gc.set_debug(flags) 设置gc的debug日志,一般设置为gc.DEBUG_LEAK 2、gc.collect([generation]) 显式进行垃圾回收,可以输入参数,0代表只检查第一代的对象, 1代表检查一,二代的对象,2代表检查一,二,三代的对象,如果不传参数, 阅读全文
posted @ 2020-05-08 00:26 Hany47315 编辑
摘要:''' partial引用函数,并增加形参 ''' import functools def show_arg(*args,**kwargs): print("args",args) print("kwargs",kwargs) q = functools.partial(show_arg,1,2, 阅读全文
posted @ 2020-05-08 00:25 Hany47315 编辑
摘要:from time import ctime,sleep def Clock(func): def clock(): print("现在是:",ctime()) func() sleep(3) print("现在是:",ctime()) return clock @Clock def func(): 阅读全文
posted @ 2020-05-08 00:24 Hany47315 编辑
摘要:class Foo(object): def __init__(self, *args, **kwargs): pass def __new__(cls, *args, **kwargs): return object.__new__(cls, *args, **kwargs) # 以上return 阅读全文
posted @ 2020-05-08 00:22 Hany47315 编辑
摘要:class student(object): def __init__(self,name=None,age=None): self.name = name self.age = age def __getattribute__(self, item):#getattribute方法修改类的属性 i 阅读全文
posted @ 2020-05-08 00:21 Hany47315 编辑
摘要:import copy a = ['a','b','c'] b = a #b和a引用自同一块地址空间 print("a==b :",a==b) print("a is b :",a is b) c = copy.deepcopy(a)# 对a进行深拷贝 print("a的id值为:",id(a)) 阅读全文
posted @ 2020-05-07 21:22 Hany47315 编辑
摘要:from threading import Thread g_num = 0 def test1(): global g_num for i in range(1000000): g_num += 1 print(" test1 g_num=%d"%g_num) def test2(): globa 阅读全文
posted @ 2020-05-07 21:14 Hany47315 编辑
摘要:from multiprocessing import Pool import os,time,random def worker(msg): start_time = time.time() print("(%s)开始执行,进程号为(%s)"%(msg,os.getpid())) time.sle 阅读全文
posted @ 2020-05-07 21:13 Hany47315 编辑
摘要:# Queue的工作原理 from multiprocessing import Queue q = Queue(3)#初始化一个Queue对象,最多可接收3条put消息 q.put("Info1") q.put("Info2") print("q是否满了",q.full())#查看q是否满了 q. 阅读全文
posted @ 2020-05-07 21:11 Hany47315 编辑
摘要:# 主线程等待所有子线程结束才结束 import threading from time import sleep,ctime def sing(): for i in range(3): print("正在唱歌 %d"%(i)) sleep(2) def dance(): for i in ran 阅读全文
posted @ 2020-05-07 21:09 Hany47315 编辑
摘要:from threading import Thread def work1(nums): nums.append('a') print(' 在work1中 ',nums) def work2(nums): print(" 在work2中 ,",nums) if __name__ == '__mai 阅读全文
posted @ 2020-05-07 21:07 Hany47315 编辑
摘要:from threading import Thread import time g_num = 100 def work1(): global g_num for i in range(3): g_num += 1 print(" 在work1函数中,g_num 是 %d "%(g_num)) d 阅读全文
posted @ 2020-05-07 21:05 Hany47315 编辑
摘要:from multiprocessing import Process import os # 子进程执行的函数 def run_proc(name): print("子进程运行中,名称:%s,pid:%d..."%(name,os.getpid())) if __name__ == "__main 阅读全文
posted @ 2020-05-07 21:04 Hany47315 编辑
摘要:import gevent def f(n): for i in range(n): print (gevent.getcurrent(), i) # gevent.getcurrent() 获取当前进程 g1 = gevent.spawn(f, 3)#函数名,数目 g2 = gevent.spaw 阅读全文
posted @ 2020-05-07 21:02 Hany47315 编辑
摘要:from gevent import monkey import gevent import urllib.request #有IO操作时,使用patch_all自动切换 monkey.patch_all() def my_downLoad(file_name, url): print('GET: 阅读全文
posted @ 2020-05-07 21:00 Hany47315 编辑
摘要:""" 创建锁 mutex = threading.Lock() 锁定 mutex.acquire([blocking]) 当blocking为True时,当前线程会阻塞,直到获取到这个锁为止 默认为True 当blocking为False时,当前线程不会阻塞 释放 mutex.release() 阅读全文
posted @ 2020-05-07 20:58 Hany47315 编辑
摘要:import threading # 创建ThreadLocal对象 house = threading.local() def process_paper(): user = house.user print("%s是房子的主人,in %s"%(user,threading.current_thr 阅读全文
posted @ 2020-05-07 20:56 Hany47315 编辑
摘要:""" Process([group[,target[,name[,args[,kwargs]]]]]) group:大多数情况下用不到 target:表示这个进程实例所调用的对象 target=函数名 name:为当前进程实例的别名 args:表示调用对象的位置参数元组 args=(参数,) kw 阅读全文
posted @ 2020-05-07 20:54 Hany47315 编辑
摘要:from multiprocessing import Process import os from time import sleep def run_proc(name,age,**kwargs): for i in range(10): print("子进程运行中,名字为 = %s,年龄为 = 阅读全文
posted @ 2020-05-07 20:53 Hany47315 编辑
摘要:from multiprocessing import Pool import time import os def test(): print(" 进程池中的进程 pid=%d,ppid=%d--"%(os.getpid(),os.getppid())) for i in range(3): pr 阅读全文
posted @ 2020-05-07 20:52 Hany47315 编辑
摘要:import multiprocessing import os import time import random def copy_file(queue,file_name,source_folder_name,dest_folder_name): f_read = open(source_fo 阅读全文
posted @ 2020-05-07 20:51 Hany47315 编辑
摘要:#解决多进程死循环 import multiprocessing def deadLoop(): while True: print("Hello") pass if __name__ == '__main__': # 子进程死循环 p1 = multiprocessing.Process(targ 阅读全文
posted @ 2020-05-07 20:50 Hany47315 编辑
摘要:import threading # 导入线程库 import time from queue import Queue # 队列 class Producer(threading.Thread): # 线程的继承类,修改 run 方法 def run(self): global queue cou 阅读全文
posted @ 2020-05-07 20:48 Hany47315 编辑
摘要:''' 创建三个进程,让三个进程分别执行功能,关闭进程 Pool 创建 ,apply执行 , close,join 关闭进程 ''' from multiprocessing import Pool import os,time,random def worker(msg): # 创建一个函数,用来 阅读全文
posted @ 2020-05-07 20:47 Hany47315 编辑
摘要:re中引用分组匹配字符串 import re # 能够完成对正确的字符串的匹配 ret = re.match("<[a-zA-Z]*>\w*</[a-zA-Z]*>", "<html>hh</html>") print(ret.group()) # 如果遇到非正常的html格式字符串,匹配出错</h 阅读全文
posted @ 2020-05-07 20:44 Hany47315 编辑
摘要:$通配符,匹配字符串结尾 import re email_list = ["xiaoWang@163.com", "xiaoWang@163.comheihei", ".com.xiaowang@qq.com"] for email in email_list: ret = re.match("[\ 阅读全文
posted @ 2020-05-07 20:38 Hany47315 编辑
摘要:def binary_search(alist, item): first = 0 last = len(alist) - 1 while first <= last: midpoint = (first + last) // 2 if alist[midpoint] == item: return 阅读全文
posted @ 2020-05-07 20:17 Hany47315 编辑
摘要:二叉树的创建 class Node(object): """节点类""" def __init__(self, elem=-1, lchild=None, rchild=None): self.elem = elem self.lchild = lchild self.rchild = rchild 阅读全文
posted @ 2020-05-07 20:16 Hany47315 编辑
摘要:''' Stack() 创建一个新的空栈 push(item) 添加一个新的元素item到栈顶 pop() 弹出栈顶元素 peek() 返回栈顶元素 is_empty() 判断栈是否为空 size() 返回栈的元素个数 ''' class Stack(object): '''栈''' def __i 阅读全文
posted @ 2020-05-07 20:14 Hany47315 编辑
摘要:队列 ''' Queue() 创建一个空队列 enqueue(item) 添加元素 dequeue() 从队列头部删除一个元素 is_empty() 判断一个队列是否为空 size() 返回队列的大小 ''' class Queue(object): '''队列''' def __init__(se 阅读全文
posted @ 2020-05-07 20:12 Hany47315 编辑
摘要:单链表 ''' is_empty() 链表是否为空 length() 查询链表长度 travel() 遍历整个链表 add(item) 链表头部添加元素 append(item) 链表尾部添加元素 insert(pos,item) 指定位置添加元素 remove(item) 删除节点 search( 阅读全文
posted @ 2020-05-07 20:11 Hany47315 编辑
摘要:参数化 from pymysql import * def main(): find_name = input("请输入物品名称") conn = connect(host='localhost',port=3306,user='root',password='root',database='jin 阅读全文
posted @ 2020-05-07 20:08 Hany47315 编辑
摘要:''' 开始 创建 connection 获取cursor 执行查询,获取数据,处理数据 关闭cursor 关闭connection 结束 ''' from pymysql import * conn = connect(host='localhost',port=3306,database=han 阅读全文
posted @ 2020-05-07 20:05 Hany47315 编辑
摘要:''' 首先在未排序序列中找到最小(大)元素, 存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素, 然后放到已排序序列的末尾。以此类推,直到所有元素均排序完毕。 ''' def selection_sort(lst): n = len(lst) for i in range 阅读全文
posted @ 2020-05-07 20:04 Hany47315 编辑
摘要:''' 通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描, 找到相应位置并插入。插入排序在实现上,在从后向前扫描过程中, 需要反复把已排序元素逐步向后挪位,为最新元素提供插入空间。 ''' def insert_sort(lst): for i in range(1,len(lst)): 阅读全文
posted @ 2020-05-07 20:00 Hany47315 编辑
摘要:''' 通过一趟排序将要排序的数据分割成独立的两部分, 其中一部分的所有数据都比另一部分数据小, 再按此方法对这两部分分别进行快速排序。 步骤为: 从数列中挑出一个元素,称为"基准"(pivot), 重新排序数列,所有元素比基准值小的摆放在基准前面, 所有元素比基准值大的摆在基准的后面(相同的数可以 阅读全文
posted @ 2020-05-07 19:59 Hany47315 编辑
摘要:''' 先递归分解数组,后合并数组 将数组分解最小之后,然后合并两个有序数组。 比较两个数组最前面的数,谁小就先取谁, 取了之后相应的指针就向后移一位,然后再比较,直到一个数组为空 最后把另一个数组的剩余部分添加过来 ''' def merge_sort(alist): if len(alist) 阅读全文
posted @ 2020-05-07 19:58 Hany47315 编辑
摘要:''' 将数组列在一个表中,分别进行插入排序。先以步长为一半,列表。然后对每一列进行排序。 然后将排好序的,再按照步长为一半,列表进行排序。 最后进行插入排序 ''' def shell_sort(lst): n = len(lst) gap = n//2 #按照总长度的一半进行分列,然后进行 行排 阅读全文
posted @ 2020-05-07 19:56 Hany47315 编辑
摘要:''' 冒泡排序算法的运作如下: 比较相邻的元素。如果第一个比第二个大(升序),就交换他们两个。 对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。最后的元素会是最大的数。 针对所有的元素重复以上的步骤,除了最后一个。 持续每次对越来越少的元素重复上面的步骤,直到没有任何一对数字需要比较。 阅读全文
posted @ 2020-05-07 19:53 Hany47315 编辑
摘要:文件写操作 ''' w 写入操作 如果文件存在,则清空内容后进行写入,不存在则创建 a 写入操作 如果文件存在,则在文件内容后追加写入,不存在则创建 with 使用 with 语句后,系统会自动关闭文件并处理异常 ''' # import os # print(os.path) # <module 阅读全文
posted @ 2020-05-07 19:50 Hany47315 编辑
摘要:lst = [[1,2,3],[4,5,6],[8,2]] # print(max(max(lst))) print(max(max(lst,key=lambda x : max(x)))) # 8 max(max( ... )) 有几层列表就存在 几个 max 嵌套 2020-05-07 阅读全文
posted @ 2020-05-07 19:45 Hany47315 编辑
摘要:dic_1 = {'a':111,'b':222} dic_2 = {'c':333,'d':444} dic = {**dic_1,**dic_2} print(dic) # {'a': 111, 'b': 222, 'c': 333, 'd': 444} {**字典名,**字典名2} 进行合并字 阅读全文
posted @ 2020-05-07 19:43 Hany47315 编辑
摘要:''' abs函数:如果参数为实数,则返回绝对值 如果参数为复数,则返回复数的模 ''' a = 6 b = -6 c = 0 # print("a = {0} , b = {1} , c = {2}".format(abs(a),abs(b),abs(c))) # a = 6 , b = 6 , 阅读全文
posted @ 2020-05-07 19:41 Hany47315 编辑
摘要:txt = '我是字符串' txt_encode = txt.encode() print(txt) # 我是字符串 print(txt_encode) # b'\xe6\x88\x91\xe6\x98\xaf\xe5\xad\x97\xe7\xac\xa6\xe4\xb8\xb2' print(t 阅读全文
posted @ 2020-05-07 19:37 Hany47315 编辑
摘要:# WSGI服务器调用 def application(environ,start_response): start_response('200 OK',[('Content-Type','text/html')]) return 'Hello World' ''' environ: 包含HTTP请 阅读全文
posted @ 2020-05-07 19:35 Hany47315 编辑
摘要:import time # WSGI允许开发者自由搭配web框架和web服务器 def app(environ,start_response): status = '200 OK' response_headers = [('Content-Type','text/html')] start_res 阅读全文
posted @ 2020-05-07 19:34 Hany47315 编辑
摘要:""" 创建udp连接 发送数据给 """ from socket import * # 创建udp套接字,使用SOCK_DGRAM udp_socket = socket(AF_INET,SOCK_DGRAM) # 准备接收方的地址 dest_addr = ('',8080)#主机号,固定端口号 阅读全文
posted @ 2020-05-07 19:32 Hany47315 编辑
摘要:""" 建立->绑定本地ip地址和端口号->接收数据->转码输出->关闭客户端 """ from socket import * udp_socket = socket(AF_INET,SOCK_DGRAM) # 绑定本地的相关信息,如果网络程序不绑定,则系统会随机分配 # UDP使用SOCK_DG 阅读全文
posted @ 2020-05-07 19:31 Hany47315 编辑
摘要:""" 建立tcp服务器 绑定本地服务器信息(ip地址,端口号) 进行监听 获取监听数据(监听到的客户端和地址) 使用监听到的客户端client_socket获取数据 输出获取到的数据 并返回给客户端一个数据 关闭服务器端 """ from socket import * # 创建tcp socke 阅读全文
posted @ 2020-05-07 19:30 Hany47315 编辑
摘要:""" 创建客户端 绑定服务器ip地址和端口号(端口号是整型) 与服务器建立连接 发送给服务器要发送的数据(转码) 接收服务器返回的数据 关闭客户端 """ from socket import * # 创建tcp socket tcp_client_socket = socket(AF_INET, 阅读全文
posted @ 2020-05-07 19:28 Hany47315 编辑
摘要:我会尽快将以前打过的代码都发布出来,然后 抓紧学习 Django ~ 😂随时复习,电脑复习有点不方便了 2020-05-07 阅读全文
posted @ 2020-05-07 19:27 Hany47315 编辑
摘要:import numpy as np n = np.array(([1,2,3],[4,5,6],[7,8,9])) ''' array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) ''' # 第一行元素 n[0] # array([1, 2, 3]) # 第一行第三列元素 阅读全文
posted @ 2020-05-07 19:18 Hany47315 编辑
摘要:import numpy as np x = np.array((1,2,3,4,5)) # 使用 * 进行相乘 x*2 # array([ 2, 4, 6, 8, 10]) # 使用 / 进行相除 x / 2 # array([0.5, 1. , 1.5, 2. , 2.5]) 2 / x # a 阅读全文
posted @ 2020-05-07 19:10 Hany47315 编辑
摘要:import numpy as np # 将 0~100 10等分 x = np.arange(0,100,10) # array([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90]) # 每个数组元素对应的正弦值 np.sin(x) ''' array([ 0. , 阅读全文
posted @ 2020-05-07 19:07 Hany47315 编辑
摘要:import numpy as np x = np.array([1,4,5,2]) # array([1, 4, 5, 2]) # 返回排序后元素的原下标 np.argsort(x) # array([0, 3, 1, 2], dtype=int64) # 输出最大值的下标 x.argmax( ) 阅读全文
posted @ 2020-05-07 19:06 Hany47315 编辑
摘要:import numpy as np n = np.arange(10) # array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) # 查看数组的大小 n.size # 10 # 将数组分为两行五列 n.shape = 2,5 ''' array([[0, 1, 2, 3, 4 阅读全文
posted @ 2020-05-07 19:04 Hany47315 编辑
摘要:# 导入numpy 并赋予别名 np import numpy as np # 创建数组的常用的几种方式(列表,元组,range,arange,linspace(创建的是等差数组),zeros(全为 0 的数组),ones(全为 1 的数组),logspace(创建的是对数数组)) # 列表方式 n 阅读全文
posted @ 2020-05-07 19:02 Hany47315 编辑
摘要:import numpy as np x = np.arange(8) # [0 1 2 3 4 5 6 7] # 在数组尾部追加一个元素 np.append(x,10) # array([ 0, 1, 2, 3, 4, 5, 6, 7, 10]) # 在数组尾部追加多个元素 np.append(x 阅读全文
posted @ 2020-05-07 19:00 Hany47315 编辑
摘要:import numpy as np # 生成一个随机数组 np.random.randint(0,6,3) # array([1, 1, 3]) # 生成一个随机数组(二维数组) np.random.randint(0,6,(3,3)) ''' array([[4, 4, 1], [2, 1, 0 阅读全文
posted @ 2020-05-07 18:59 Hany47315 编辑
摘要:# 重采样 多索引 标准差 协方差 import pandas as pd import numpy as np import copy # 设置列对齐 pd.set_option("display.unicode.ambiguous_as_wide",True) pd.set_option("di 阅读全文
posted @ 2020-05-07 18:58 Hany47315 编辑
摘要:# C:\Users\lenovo\Desktop\总结\Python # 读取 Excel 文件并进行筛选 import pandas as pd # 设置列对齐 pd.set_option("display.unicode.ambiguous_as_wide",True) pd.set_opti 阅读全文
posted @ 2020-05-07 18:55 Hany47315 编辑
摘要:# 查看数据特征和统计信息 import pandas as pd # 读取文件 dataframe = pd.read_excel(r'C:\Users\lenovo\Desktop\总结\Python\超市营业额.xlsx') # 查看所有的交易额信息 dataframe['交易额'].desc 阅读全文
posted @ 2020-05-07 18:54 Hany47315 编辑
摘要:对Series 对象使用匿名函数 使用 pipe 函数对 Series 对象使用 匿名函数 pd.Series(range(5)).pipe(lambda x,y,z :(x**y)%z,2,5) pd.Series(range(5)).pipe(lambda x:x+3).pipe(lambda 阅读全文
posted @ 2020-05-07 18:52 Hany47315 编辑
摘要:# 时间序列和常用操作 import pandas as pd # 每隔五天--5D pd.date_range(start = '20200101',end = '20200131',freq = '5D') ''' DatetimeIndex(['2020-01-01', '2020-01-06 阅读全文
posted @ 2020-05-07 18:49 Hany47315 编辑
摘要:import pandas as pd # 设置列对齐 pd.set_option("display.unicode.ambiguous_as_wide",True) pd.set_option("display.unicode.east_asian_width",True) # 读取工号姓名时段交 阅读全文
posted @ 2020-05-07 18:48 Hany47315 编辑
摘要:import pandas as pd import numpy as np # 读取全部数据,使用默认索引 data = pd.read_excel(r'C:\Users\lenovo\Desktop\总结\Python\超市营业额.xlsx') # 修改异常值 data.loc[data.交易额 阅读全文
posted @ 2020-05-07 18:46 Hany47315 编辑
摘要:# 处理异常值缺失值重复值数据差分 import pandas as pd import numpy as np import copy # 设置列对齐 pd.set_option("display.unicode.ambiguous_as_wide",True) pd.set_option("di 阅读全文
posted @ 2020-05-07 18:44 Hany47315 编辑
摘要:# 分组与聚合 import pandas as pd import numpy as np # 设置列对齐 pd.set_option("display.unicode.ambiguous_as_wide",True) pd.set_option("display.unicode.east_asi 阅读全文
posted @ 2020-05-07 18:41 Hany47315 编辑
摘要:# 使用透视表与交叉表查看业绩汇总数据 import pandas as pd import numpy as np import copy # 设置列对齐 pd.set_option("display.unicode.ambiguous_as_wide",True) pd.set_option(" 阅读全文
posted @ 2020-05-07 18:36 Hany47315 编辑
摘要:C:\Users\lenovo\Desktop\总结\Python\超市营业额.xlsx 这个文档自己创建就可以,以下几篇文章仅作为参考 import pandas as pd import copy # 设置列对齐 pd.set_option("display.unicode.ambiguous_ 阅读全文
posted @ 2020-05-07 18:33 Hany47315 编辑
摘要:# 一维数组与常用操作 import pandas as pd # 设置输出结果列对齐 pd.set_option('display.unicode.ambiguous_as_wide',True) pd.set_option('display.unicode.east_asian_width',T 阅读全文
posted @ 2020-05-07 18:31 Hany47315 编辑
摘要:# DateFrame 的创建,包含部分:index , column , values import numpy as np import pandas as pd # 创建一个 DataFrame 对象 dataframe = pd.DataFrame(np.random.randint(1,2 阅读全文
posted @ 2020-05-07 18:29 Hany47315 编辑
摘要:连接 mysql 驱动 mysq1-client python2,3都能直接使用 对myaq1安装有要求,必须指定位置存在 配置文件 python-mysql python3 不支持 pymysql python2, python3都支持 还可以伪装成前面的库 2020-05-07 阅读全文
posted @ 2020-05-07 18:07 Hany47315 编辑
摘要:在项目的 settings 中修改 DATABASES = { 'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 'ENGINE':'djang 阅读全文
posted @ 2020-05-07 18:05 Hany47315 编辑
摘要:查找所有的元素 Student.objects.all() 查找单个元素 Student.objects.get(主键=值) 主键 pk = xxx 更新数据库数据后进行保存 stu.save() 删除数据库表中的行 stu.delete() 需要注意的点: update_student 函数和 d 阅读全文
posted @ 2020-05-07 17:42 Hany47315 编辑
摘要:安装 you-get 和 ffmpeg ffmpeg 主要是下载之后,合并音频和视频 pip install you-get -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com pip install ffmpeg -i 阅读全文
posted @ 2020-05-07 16:29 Hany47315 编辑
摘要:[] 和 () 创建的列表推导式不同 lst = [i for i in range(4)] print(lst) print(type(lst)) gen = (i for i in range(4)) print(gen) print(type(gen)) 对 () 创建的对象进行遍历 gen 阅读全文
posted @ 2020-05-07 13:02 Hany47315 编辑
摘要:在 views 中实现对数据库的添加和读取数据库 添加数据 对象 = models 中创建的类名() 对象.列名 = '字段值' 对象.save() 进行保存 return HttpResponse('提示信息') def add_student(request): stu = Student() 阅读全文
posted @ 2020-05-07 11:40 Hany47315 编辑
摘要:流程:1.用户需求分析 2.概念结构设计 3.逻辑结构设计(规范化) 4.数据库的物理结构设计 E-R 模型 -> 关系数据模型步骤①为每个实体建立-张表 ②为每个表选择一一个主键(建议添加一-个没有实际意义的字段作为主键) ③使用外键表示实体间关系 ④定义约束条件 ⑤评价关系的质量,并进行必要的改 阅读全文
posted @ 2020-05-07 10:46 Hany47315 编辑
摘要:在 创建好的 app 目录下的 models.py 中,编写创建 数据库表的限制条件 class Student(models.Model): s_name = models.CharField(max_length=16) s_age = models.IntegerField(default=1 阅读全文
posted @ 2020-05-07 09:40 Hany47315 编辑
摘要:对于一个对象: list(对象) 可以进行强制转换 [对象] 不能够进行强制转换,只是在外围加上 [ ] 列表推导式中相同 2020-05-06 阅读全文
posted @ 2020-05-06 18:27 Hany47315 编辑
摘要:写在前面的话,不是我不想用 Linux 去运行 Django Windows 的坑很多,可是 Linux 太慢了 以后遇到的坑,我都会发出来,供大家参考的. python manage.py runserver 运行出错hostname, aliases, ipaddrs = gethostbyad 阅读全文
posted @ 2020-05-06 16:46 Hany47315 编辑

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