摘要: 写在前面的话,不是我不想用 Linux 去运行 Django Windows 的坑很多,可是 Linux 太慢了 以后遇到的坑,我都会发出来,供大家参考的. python manage.py runserver 运行出错hostname, aliases, ipaddrs = gethostbyad 阅读全文
posted @ 2020-05-06 16:46 Hany47315 阅读(130) 评论(0) 推荐(0)
摘要: 111.requests.get 方法的流程 r = requests.get('https://www.baidu.com/').content.decode('utf-8') 从状态码到 二进制码到 utf-8 编码 112.对 soup 对象进行美化 html = soup.prettify( 阅读全文
posted @ 2020-05-06 15:41 Hany47315 阅读(137) 评论(0) 推荐(0)
摘要: 100: ('continue',), 101: ('switching_protocols',), 102: ('processing',), 103: ('checkpoint',), 122: ('uri_too_long', 'request_uri_too_long'), 200: ('o 阅读全文
posted @ 2020-05-06 11:04 Hany47315 阅读(135) 评论(0) 推荐(0)
摘要: 普通写法 { 对象的操作 for 对象 in 可迭代对象 } 2020-05-04 阅读全文
posted @ 2020-05-04 21:23 Hany47315 阅读(321) 评论(0) 推荐(0)
摘要: 普通写法 { 对象对 键的操作:对象对 值的操作 for 对象 in 字典 的keys() 或者 values() 或者 items() 方法 } 2020-05-04 阅读全文
posted @ 2020-05-04 21:19 Hany47315 阅读(300) 评论(0) 推荐(0)
摘要: 普通写法: [对象 for 对象 in 可迭代对象] [对象 for 对象 in 可迭代对象 if 条件] 对象可以进行表达式运算 2020-05-04 阅读全文
posted @ 2020-05-04 20:52 Hany47315 阅读(190) 评论(0) 推荐(0)
摘要: 装饰器:通俗理解:修改其他函数的功能的函数 学习装饰器之前,下面的点都要掌握 1.万物皆对象,当将函数名赋值给另一个对象之后 原来的对象删除,不会影响赋值过的新对象 2.函数内定义函数 注:外部函数返回内部函数,内部函数调用外部函数的参数 才可以称为闭包 3.从函数中返回函数,外部定义的函数返回内部 阅读全文
posted @ 2020-05-04 20:44 Hany47315 阅读(157) 评论(0) 推荐(0)
摘要: 条件为真执行的语句 if 条件 else 条件为假执行的语句注:执行的语句,单独包含一个关键字时可能会出错 使用关键字导致报错问题 原因是因为 print(pass) pass 为关键字,不可以直接输出 2020-05-04 阅读全文
posted @ 2020-05-04 20:02 Hany47315 阅读(128) 评论(0) 推荐(0)
摘要: reduce 返回的往往是一整个可迭代对象的 操作结果reduce(函数,可迭代对象)注:lambda x,y 两个参数 2020-05-04 阅读全文
posted @ 2020-05-04 19:52 Hany47315 阅读(300) 评论(0) 推荐(0)
摘要: filter 返回一个符合要求的元素所构成的新列表 filter(函数,可迭代对象) map 和 filter 混合使用将 lst_num 中为偶数的取出来进行加2 和 乘2 操作 2020-05-04 阅读全文
posted @ 2020-05-04 19:44 Hany47315 阅读(494) 评论(0) 推荐(0)
摘要: map(需要对对象使用的函数,要操作的对象) 函数可以是自定义的,也可以是内置函数的,或者 lambda 匿名函数 操作的对象多为 可迭代对象可以是函数名的列表集合 2020-05-04 阅读全文
posted @ 2020-05-04 19:26 Hany47315 阅读(593) 评论(0) 推荐(0)
摘要: 迭代器: 只要定义了 __next__方法,就是一个迭代器 生成器也是一种迭代器,但是只能迭代一次,因为只保存一次值 yield anext(yield 对象) 进行遍历 可迭代对象: 只要定义了 __iter__ 方法就是一个可迭代对象 列表,字符串,元组,字典和集合都是可迭代对象 使用 iter 阅读全文
posted @ 2020-05-04 19:14 Hany47315 阅读(1583) 评论(0) 推荐(0)
摘要: ''' 生成器求斐波那契数列 不需要担心会使用大量资源 ''' def fibon(n): a = b = 1 for i in range(n): yield a # a 为每次生成的数值 a,b = b,a+b for x in fibon(1000000): print(x) ''' 使用列表 阅读全文
posted @ 2020-05-04 19:01 Hany47315 阅读(127) 评论(0) 推荐(0)
摘要: def cast_list(val): print(val) # foo # [1] # ('foo', 'bar') print(type(val)) # <class 'str'> # <class 'list'> # <class 'tuple'> print(isinstance(val,( 阅读全文
posted @ 2020-05-03 14:10 Hany47315 阅读(140) 评论(0) 推荐(0)
摘要: def capitalize_every_word(s): print(s) # hello world! print(s.title()) capitalize_every_word('hello world!') # Hello World! 2020-05-03 阅读全文
posted @ 2020-05-03 14:01 Hany47315 阅读(239) 评论(0) 推荐(0)
摘要: def capitalize(s, lower_rest=False): # print(s) # fooBar # fooBar # print(s.upper()) # FOOBAR # FOOBAR # print(s[:1].upper()) # F # F # print(s[1:].lo 阅读全文
posted @ 2020-05-03 13:58 Hany47315 阅读(250) 评论(0) 推荐(0)
摘要: from re import sub def camel(s): print(s) # some_database_field_name # Some label that needs to be camelized # some-javascript-property # some-mixed_s 阅读全文
posted @ 2020-05-03 13:48 Hany47315 阅读(149) 评论(0) 推荐(0)
摘要: def byte_size(s): print(s) # 😀 # Hello World print(s.encode('utf-8')) # b'\xf0\x9f\x98\x80' # b'Hello World' print(len(s.encode('utf-8'))) # 4 11 byt 阅读全文
posted @ 2020-05-03 13:34 Hany47315 阅读(454) 评论(0) 推荐(0)
摘要: def bifurcate_by(lst, fn): print(lst) # ['beep', 'boop', 'foo', 'bar'] print(fn('baby')) # True print(fn('abc')) # False print([ [x for x in lst if fn 阅读全文
posted @ 2020-05-03 13:31 Hany47315 阅读(136) 评论(0) 推荐(0)
摘要: def bifurcate(lst, filter): print(lst) # ['beep', 'boop', 'foo', 'bar'] print(filter) # [True, True, False, True] # 列表名,不是 filter 函数 print(enumerate(l 阅读全文
posted @ 2020-05-03 13:27 Hany47315 阅读(114) 评论(0) 推荐(0)
摘要: def average(*args): print(args) # (1, 2, 3) # (1, 2, 3) print(len(args)) # 3 # 3 print(sum(args, 0.0) / len(args)) average(*[1, 2, 3]) # 2.0 average(1 阅读全文
posted @ 2020-05-03 13:20 Hany47315 阅读(946) 评论(0) 推荐(0)
摘要: def all_unique(lst): print(lst,len(lst)) # [1, 2, 3, 4, 5, 6] 6 # [1, 2, 2, 3, 4, 5] 6 print(set(lst),len(set(lst))) # {1, 2, 3, 4, 5, 6} 6 # {1, 2, 3 阅读全文
posted @ 2020-05-03 13:17 Hany47315 阅读(170) 评论(0) 推荐(0)
摘要: def all_equal(lst): print(lst[:]) # [1, 2, 3, 4, 5, 6] # [1, 1, 1, 1] print(lst[::-1]) # [6, 5, 4, 3, 2, 1] # [1, 1, 1, 1] print(lst[1:] == lst[:-1]) 阅读全文
posted @ 2020-05-03 13:12 Hany47315 阅读(124) 评论(0) 推荐(0)
摘要: # 一维数组与常用操作 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-03 12:45 Hany47315 阅读(357) 评论(0) 推荐(0)
摘要: # 导入numpy 并赋予别名 np import numpy as np # 创建数组的常用的几种方式(列表,元组,range,arange,linspace(创建的是等差数组),zeros(全为 0 的数组),ones(全为 1 的数组),logspace(创建的是对数数组)) # 列表方式 n 阅读全文
posted @ 2020-05-03 12:44 Hany47315 阅读(260) 评论(0) 推荐(0)
摘要: 1.打开网页 urllib.request.urlopen('网址') 例:response = urllib.request.urlopen('http://www.baidu.com/') 返回值为 <http.client.HTTPResponse object at 0x00000224EC 阅读全文
posted @ 2020-05-02 21:15 Hany47315 阅读(529) 评论(0) 推荐(0)
摘要: import heapq class PriorityQueue: def __init__(self): self._queue=[] self._index=0 def push(self,item,priority): heapq.heappush(self._queue,(-priority 阅读全文
posted @ 2020-05-02 20:47 Hany47315 阅读(120) 评论(0) 推荐(0)
摘要: def dedupe(items,key=None): seen = set() for item in items: val = item if key==None else key(item) #item是否为字典,是则转化为字典key(item),匿名函数调用 if val not in se 阅读全文
posted @ 2020-05-02 20:44 Hany47315 阅读(140) 评论(0) 推荐(0)
摘要: '''format(数字,str(算术式)+"d或者f") d 表示 int f 表示 float ''' format(5,str(2*4)+"d") ' 5' format(5,str(2*4)+"f") '5.000000' '''使用 .2f 控制小数点个数''' format(5,str( 阅读全文
posted @ 2020-04-30 08:53 Hany47315 阅读(134) 评论(0) 推荐(0)
摘要: 常用国内源 清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:https://mirrors.aliyun.com/pypi/simple/ 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 华中理工大学:h 阅读全文
posted @ 2020-04-29 15:07 Hany47315 阅读(123) 评论(0) 推荐(0)
摘要: 出什么错了,直接卸载 Python ,重新安装就好了!! 2020-04-27 阅读全文
posted @ 2020-04-27 17:12 Hany47315 阅读(132) 评论(0) 推荐(0)
摘要: ''' 计算 1.输入半径,输出面积和周长 2.输入面积,输出半径及周长 3.输入周长,输出半径及面积 ''' # # 1.输入半径,输出面积和周长 # from math import pi # # # 定义半径 # r = int(input("请输入半径的值(整数)")) # if r < 0 阅读全文
posted @ 2020-04-27 16:53 Hany47315 阅读(1431) 评论(0) 推荐(0)
摘要: # 安装 pip 包 from tkinter import * def getBao(): pip = 'pip install %s -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com'%entry_bao.get() 阅读全文
posted @ 2020-04-27 10:54 Hany47315 阅读(126) 评论(0) 推荐(0)
摘要: pip install 包名 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com 2020-04-27 pip install -r requirements.txt -i http://pypi.mirrors.ustc 阅读全文
posted @ 2020-04-27 10:33 Hany47315 阅读(114) 评论(0) 推荐(0)
摘要: 1.打开 Data Source alt insert 打开 Data Source 找到 db.sqlite3 确定 Download 下载后 TestConnection 测试是否成功 2.项目下的 urls.py 文件 urlpatterns 匹配网页集合 写法 url(正则,views.函数 阅读全文
posted @ 2020-04-26 12:49 Hany47315 阅读(168) 评论(0) 推荐(0)
摘要: 1.导入 Django 工程时 在 manage.py 上一级目录导入 2.Add local 本地 Add Remote 远端 3.BASE_DIR 项目所在目录的绝对路径 4.SECRET_KEY 相当于密钥 5.项目开发后->进行测试->演示环境->上线生产环境 6.DEBUG = True 阅读全文
posted @ 2020-04-25 21:07 Hany47315 阅读(123) 评论(0) 推荐(0)
摘要: 1.脚本不能随便运行,没准 linux 运行完就上不去了 2.pip 在 linux 上 写 pip3 同理 python 写为 python3 3.在 pycharm 上安装库之后,在命令提示符中依旧需要安装 才能在终端进行使用 4.在虚拟环境下安装 uwsgi 5.升级 django 到2.0版 阅读全文
posted @ 2020-04-25 19:59 Hany47315 阅读(162) 评论(0) 推荐(0)
摘要: import random def load_config(path): with open(path,'r') as tou: return [line for line in tou.readlines()] headers = { 'User-Agent':load_config('usera 阅读全文
posted @ 2020-04-25 00:52 Hany47315 阅读(331) 评论(0) 推荐(0)
摘要: import datetime def date_delta(start, end): # 转换为标准时间 start = datetime.datetime.strptime(start,"%Y-%m-%d %H:%M:%S") end = datetime.datetime.strptime(e 阅读全文
posted @ 2020-04-24 23:20 Hany47315 阅读(701) 评论(0) 推荐(0)
摘要: import datetime import sys def next_day(date_str): date = datetime.datetime.strptime(date_str, '%Y-%m-%d') return (date + datetime.timedelta(days=1)). 阅读全文
posted @ 2020-04-24 23:17 Hany47315 阅读(134) 评论(0) 推荐(0)