随笔分类 - Python
摘要:import time print(time.strftime('%Y/%m/%d %H:%M:%S', time.localtime())) # 2022/06/27 20:55:56
阅读全文
摘要:lists = [1, 2, 3, 4, 5, 6, 7] print(list(filter(lambda x: x > 4, lists))) # [5, 6, 7] print(list(map(lambda x: x > 4, lists))) # [False, False, False,
阅读全文
摘要:def get_last_line(file_name): offset = -10 with open(file_name, 'rb') as f: # 读取方式要以字节读取 while 1: """ f.seek(off, whence=0):从文件中移动off个操作标记(文件指针),正往结束方
阅读全文
摘要:ip2long = lambda x: sum([256 ** j * int(i) for j, i in enumerate(x.split('.')[::-1])]) long2ip = lambda x: '.'.join(['{:0>3d}'.format(x // (256 ** i)
阅读全文
摘要:ip2long = lambda x: sum([256 ** j * int(i) for j, i in enumerate(x.split('.')[::-1])]) long2ip = lambda x: '.'.join(['{:0>3d}'.format(x // (256 ** i)
阅读全文
摘要:大文件直接用read()函数会内存溢出 解决办法 1. 一行一行的取 with open('t1.txt') as f: while True: data = f.readline() # 判断文件是否结束 if not data: break # 优化版 with open('t1.txt') a
阅读全文
posted @ 2022-03-01 20:44
xuecl
摘要:先安装fake_useragent模块 pip install fake_useragent 代码 from fake_useragent import UserAgent ua = UserAgent() ua.ie # Mozilla/5.0 (Windows; U; MSIE 9.0; Win
阅读全文
摘要:##requirements.txt文件记录了项目所依赖的包以及版本,方便在新环境导入 生成requirements.txt文件 pip freeze > requirements.txt 在新环境导入依赖包 pip install -r requirements.txt
阅读全文
摘要:from selenium import webdriver from selenium.webdriver.common.keys import Keys # 拿到键盘的按键 # 通过 webdriver 拿到 Chrome 对象 web = webdriver.Chrome(executepat
阅读全文
摘要:import time import requests # 返回视频的真实下载地址 def get_real_video_url(video_id): # 视频地址解析接口 url = 'https://www.pearvideo.com/videoStatus.jsp?contId={}'.for
阅读全文
摘要:import time import random from selenium import webdriver def crawl(): # 网易云音乐 只要平凡 url = 'https://music.163.com/#/song?id=574919767' # 拿到chrome参数配置对象
阅读全文
摘要:https://www.runoob.com/w3cnote/python-func-decorators.html
阅读全文
摘要:转:http://www.pythondoc.com/pythontutorial3/index.html#python
阅读全文
摘要:用命令 pip install django==2.1.0 装不上, 怎么办? 这样就可以了:pip install 包名 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
阅读全文
摘要:转:https://www.cnblogs.com/dylancao/p/10219956.html 一般Ubuntu默认的Python版本都为2.x, 如何改变Python的默认版本呢?假设我们需要把Python3.5设置为默认版本:首先查看Python默认版本: ubuntu@user~$:py
阅读全文
摘要:https://www.cnblogs.com/an-ning0920/p/10037790.html
阅读全文
摘要:引言 在一台PC开发多个项目,有些项目依赖的环境可能会有冲突(比如:一个项目需要某包的1.0版本,另一个项目需要该包的2.0版本,1.0与2.0不能共存),根据项目需要来回安装卸载很麻烦,这时就可以使用虚拟环境来解决这个问题。 虚拟环境(位于/home/.virtualenvs) 安装 sudo p
阅读全文
摘要:#!/usr/bin/env python #test.py print("hello") 用于指定运行该脚本的Python解释器,Linux专用,windows不需要。env方式下,系统会自动使用环境变量里指向的Python。还有一种方式,#!/usr/bin/python3.6,这会强制要求使用
阅读全文
摘要:方法一:把光标放在待查函数上,按ctrl+b 方法二:按住ctrl,鼠标点击待查函数
阅读全文
浙公网安备 33010602011771号