随笔分类 - python
摘要:import os rootdir = '/media/Stanford3dDataset_v1.2_Aligned_Version' for root,dirs,files in os.walk(rootdir): for dir in dirs: print(os.path.join(root,
阅读全文
摘要:1、Slicing s = ' hello ' s = s[:] print(s) # hello s = ' hello ' s = s[3:8] print(s) # hello 2、strip() s = ' hello '.strip() print(s) # hello s = '###h
阅读全文
摘要:我这里使用的是CentOS7,默认系统自带python2.7的版本,这个版本被系统很多程序所依赖,所以不建议删除,如果使用最新的Python3那么我们知道编译安装源码包和系统默认包之间是没有任何影响的,所以可以安装python3和python2共存 1、安装依赖包 1)首先安装gcc编译器,gcc有
阅读全文
摘要:在python3中,主要借助pymysql进行MySQL操作,简单记录下基本的操作步骤: 操作流程一般分为3步: 1. 建立数据库连接; 2. 执行操作(查询、插入、更新、删除等) 3. 关闭连接 这里直接贴代码了,用函数的形式进行表述了: import pymysql # 数据库连接 def co
阅读全文
摘要:1、for循环中的else条件 这是一个for-else方法,循环遍历列表时使用else语句。 下面举个例子,比如我们想检查一个列表中是否包含奇数。 那么可以通过for循环,遍历查找。 numbers = [2, 4, 6, 8, 1] for number in numbers: if numbe
阅读全文
摘要:import uiautomator2 as ui import time def douyin(): try: # 通过usb连接 d = ui.connect_usb() # 打开抖音 if d(text="抖音").exists: d(text="抖音").click() time.sleep
阅读全文
摘要:import requests from lxml import etree from hashlib import md5 import re import os import redis r = redis.StrictRedis(host='localhost', port=6379, db=
阅读全文
摘要:常用的读取文件函数有三种read()、readline()、readlines() read() 一次性读全部内容 一次性读取文本中全部的内容,以字符串的形式返回结果 with open("test.txt", "r") as f: # 打开文件 data = f.read() # 读取文件 pri
阅读全文
摘要:1、String 操作 set() #在Redis中设置值,默认不存在则创建,存在则修改 r.set('name', 'zhangsan') '''参数: set(name, value, ex=None, px=None, nx=False, xx=False) ex,过期时间(秒) px,过期时
阅读全文
摘要:使用技术 python正则匹配 Beautifulsoup4库 xpath解析 正则匹配 和JavaScript语言匹配方式类似 使用前需导入re包 有几种正则匹配的方法:match, search, compile, findall, finditer re.match(a, b, c) 三个参数
阅读全文
摘要:正则表达式(Regular Expression,在代码中常简写为regex、 regexp、RE 或re)是预先定义好的一个“规则字符率”,通过这个“规则字符串”可以匹配、查找和替换那些符合“规则”的文本。 虽然文本的查找和替換功能可通过字符串提供的方法实现,但是实现起来极为困难,而且运算效率也很
阅读全文
摘要:大家好,我是老表~ 本文中介绍的字符串一个非常重要的知识点:字符串格式化输出。 格式化怎么理解?简答来说:就是让字符串按照我们设定的格式来输出,达到我们想要的结果。主要是有4种方式: %:基于占位符的格式化 format()函数的格式化:重点掌握 f-string格式化:重点掌握 字符串模板函数st
阅读全文
摘要:内置函数就是Python给你提供的,拿来直接用的函数,比如print.,input等。 截止到python版本3.6.2 ,python一共提供了68个内置函数,具体如下👇 abs() dict() help() min() setattr() all() dir() hex() next() s
阅读全文
摘要:# -*- coding: UTF-8 -*- from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support impor
阅读全文
摘要:代码示例 import pymysql pymysql.connect(host='localhost',user='user',password='password',database='database',port=3306) from pymysql import connect, Error
阅读全文
摘要:1、for循环中的else条件 这是一个for-else方法,循环遍历列表时使用else语句。 下面举个例子,比如我们想检查一个列表中是否包含奇数。 那么可以通过for循环,遍历查找。 numbers = [2, 4, 6, 8, 1] for number in numbers: if numbe
阅读全文