随笔分类 -  Python 基础

url参数值编码
摘要:16. url参数路径编码 示例: AM95C60-20GC/30 为路径中一段,完整url:https://blog.csdn.net/AM95C60-20GC/30 ,如果这样访问将报404错误,转换代码后为AM95C60-20GC%2F30: import urllib urllib.pars 阅读全文

posted @ 2023-07-10 10:18 花阴偷移 阅读(7) 评论(0) 推荐(0) 编辑

python xml操作
摘要:1) 导入import xml.etree.ElementTree as ET 2)需要一个xml文件(sensorexpert_brand.xml),结构如下所示: <?xml version="1.0" encoding="UTF-8"?> <response> <error>0</error> 阅读全文

posted @ 2023-05-30 10:16 花阴偷移 阅读(4) 评论(0) 推荐(0) 编辑

python中判断json的key是否存在,以及动态获取key和value
摘要:import json body={'discountPrice':{'1':'5.4847','59':'5.1938','100':'4.9030'}} #将dict类型的数据转换成str jsDumps=json.dumps(body) jsLoads = json.loads(jsDumps 阅读全文

posted @ 2022-12-30 16:10 花阴偷移 阅读(3615) 评论(0) 推荐(0) 编辑

pip 安装包查看
摘要:一.centos平台 寻找pip安装包的目录方法 [root@iZwz927xptl8kw8zqrmwvcZ bin]# whereis python python: /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3.6-config / 阅读全文

posted @ 2022-12-26 12:28 花阴偷移 阅读(669) 评论(0) 推荐(0) 编辑

python 多版本查看与命令用法
摘要:1.windows查看电脑上是否有多个版本 如果python2能查到,那么用命令时 1、pip是python的包管理工具,pip和pip3版本不同,都位于Scripts\目录下: 2、如果系统中只安装了Python2,那么就只能使用pip。 3、如果系统中只安装了Python3,那么既可以使用pip 阅读全文

posted @ 2022-12-26 12:27 花阴偷移 阅读(692) 评论(0) 推荐(0) 编辑

python 异常处理 12
摘要:当python程序在执行期间发生错误时,如果编写了处理该异常的代码,程序将继续运行;如果未对异常进行处理,程序将停止并显示traceback,其中包含有关异常的报告。异常是使用try- except代码块处理的。告诉python发生异常进怎么办,在try-except代码块中出现异常,程序也将继续运 阅读全文

posted @ 2022-12-26 12:26 花阴偷移 阅读(34) 评论(0) 推荐(0) 编辑

python 文件操作 11
摘要:一.文件读取操作 1. 读取整个文件 在同级目录,创建一个pi_digits.txt文件和file_reader.py文件。 pi_digits.txt文件中加入内容 file_reader.py文件内容如下: with open('pi_digits.txt') as file_object: c 阅读全文

posted @ 2022-12-26 12:26 花阴偷移 阅读(59) 评论(0) 推荐(0) 编辑

python if语句 5
摘要:1.条件测试 cars = ['audi', 'bmw', 'subaru', 'toyota'] for car in cars: if car=='bmw': print(car.upper()) else: print(car.title()) #下面检查不相等 != top='mus' if 阅读全文

posted @ 2022-12-26 12:25 花阴偷移 阅读(9) 评论(0) 推荐(0) 编辑

python 字典 6
摘要:1. 字典增删改 #简单字典用法,用{}表示字典。键和值之间用冒号分隔,而键值对之间用逗号分隔,如下所示 alien_0={'color':'green','points':'5'} print(alien_0['color']) #字典是键值对,每个值可以是字符串,数字,列表,字典 #添加键值对 阅读全文

posted @ 2022-12-26 12:25 花阴偷移 阅读(14) 评论(0) 推荐(0) 编辑

python while 7
摘要:1. 简单的while示例 current_number=1 while current_number<=5 : print(current_number) current_number+=1 2.使用标志 active=True num =1 num_end=10 while active: pr 阅读全文

posted @ 2022-12-26 12:24 花阴偷移 阅读(15) 评论(0) 推荐(0) 编辑

python 函数 9
摘要:1.定义函数 #下面定义一个简单的函数, def关键字用来定义函数 def greet_user(username): print(f"hello-{username}") #调用 greet_user('jesse') #实参和形参,上面变量username是一个形参(parameter),gre 阅读全文

posted @ 2022-12-26 12:24 花阴偷移 阅读(17) 评论(0) 推荐(0) 编辑

python 类 10
摘要:1.创建和使用类 #在python中,首字母大写的名称指的是类 class Dog: #定义方法,该方法是一个特殊方法,每当Dog类创建新实例时,python都会自动运行它 #这个方法的名称中,开头和末尾各有两个下划线,这是一种约定。 #self是必须的形参,指本身实例的引用 def __init_ 阅读全文

posted @ 2022-12-26 12:24 花阴偷移 阅读(2) 评论(0) 推荐(0) 编辑

python 的vs code配置
该文被密码保护。

posted @ 2022-12-26 12:23 花阴偷移 阅读(1) 评论(0) 推荐(0) 编辑

python 代码语法检查
摘要:一.静态检查 我们知道python是一门脚本语言,不像C#/Java等编译型语言可以在编译阶段就报出代码错误,脚本语言往往需要在运行期执行到这段代码时才会抛出代码错误。 那么在实际商业项目中使用python开发,我们是怎样做静态代码检查的呢? 1)首先在我们项目组推荐使用vscode做为python 阅读全文

posted @ 2022-08-12 17:51 花阴偷移 阅读(853) 评论(0) 推荐(0) 编辑

Python 遍历列表、切片、元组 4
摘要:1.for循环列表 cars=['bmv','audi','toyota','subaru'] for c in cars: print(c) print(c) 需求注意的是:for循环一定要加冒号(:), 再是print必须缩进。 2.创建数值列表 #通过函数range(1,5) 生成一系列数,生 阅读全文

posted @ 2022-08-09 14:44 花阴偷移 阅读(121) 评论(0) 推荐(0) 编辑

Python 列表 3
摘要:python的列表就相当于C#的Array数组 1.访问列表元素 bycycles=['trek','cannondale','redline','specialized'] print(bycycles) print(bycycles[0]) print(bycycles[-1]) 1)声明一个列 阅读全文

posted @ 2022-08-08 11:02 花阴偷移 阅读(51) 评论(0) 推荐(0) 编辑

Python 变量和简单数据类型 2
摘要:1. print 打印 print("Hello Python world!") 2.变量 message = "Hello Python world!" print(message) 3.字符串 可以是单引号也可以是双引号 "This is a string." 'This is also a s 阅读全文

posted @ 2022-08-04 11:23 花阴偷移 阅读(27) 评论(0) 推荐(0) 编辑

阿里云 centos 8 python 3.6 升级到python 3.8
摘要:一.环境 阿里云centos 8.5 默认自带了python 3.6版本,由于很多插件更新快,需要更高的版本,这里升级到python3.10.5最新稳定版本。 1)查看python3默认版本 [root@iZwz927xptl8kw8zqrmwvcZ ~]# python3 Python 3.6.8 阅读全文

posted @ 2022-07-20 16:42 花阴偷移 阅读(2856) 评论(1) 推荐(0) 编辑

Python for windows安装 1
摘要:一.简介 Python是一种跨平台的编程语言,这意味着它能够运行在所有主流操作系统中。在所有安装了Python的现代计算机上,都能够运行你编写的任何Python程序。然而,在不同的操作系统中,安装Python的方法存在细微的差别。 Sublime Test 是一款简单的文本编辑器,可以在任何现代操作 阅读全文

posted @ 2022-07-01 15:05 花阴偷移 阅读(111) 评论(0) 推荐(0) 编辑

导航

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