
python
仰望XX
日进一步!
展开
-
python - json
版本:python3dumps: dict --> strimport jsonmy_dict = {"name": "zhangsan", "age": 22}print(type(my_dict)) # <class 'dict'>data_str = json.dumps(my_dict)print(type(data_str)) # <class 'str'>print(data_str) .原创 2021-10-27 20:22:17 · 129 阅读 · 0 评论 -
python - 特殊字符原样输出
以 \n 为例输出1)在字符串之前值直接加 r2)对于变量中包含的,使用 %r如果不这么使用,就会直接换行输出结果了# -*- coding: utf-8 -*-if __name__ == '__main__': str1 = "hello\npython" print(str1) # hello # python print('%r' % str1) # 'hello\npython' str2 = r"hello\nworld"原创 2021-09-11 07:52:55 · 2831 阅读 · 0 评论 -
python - 列表list
列表的常规使用初始化#!/usr/bin/env python3# -*- coding: utf-8 -*-def test() -> None: my_list = [1, 2, 3, "zhangSan", [3, 5]] print(my_list) # [1, 2, 3, 'zhangSan', [3, 5]] if __name__ == '__main__': test()查询#!/usr/bin/env python3# -*- co.原创 2021-08-28 23:05:11 · 208 阅读 · 0 评论 -
python - 字典dict
字典的常规使用方式整理!文章目录字典初始化type返回对象类型查询添加修改删除字典长度字典初始化#!/usr/bin/env python3# -*- coding: utf-8 -*-def test() -> None: # 方式1:空字典 my_dict1: dict = {} # 方式2 my_dict2: dict = { "name": "zhangSan", "age": "23", } .原创 2021-08-28 22:38:11 · 101 阅读 · 0 评论 -
Flask
版本flask版本:1.1.4flask-script版本:2.0.6flask-blueprint版本:1.3.0flask-script 模块manager.pyfrom flask import Flaskfrom flask_script import Managerapp = Flask(__name__)manager = Manager(app=app)@app.route('/')def index(): return 'hello world!'i原创 2021-08-24 00:22:51 · 3669 阅读 · 1 评论 -
python 时间转换操作
使用python时,写一些时间转换的时候会用到,故整理成博文,以便后续直接拷贝使用!当前时间戳:import timeprint(time.time()) # 1622180171.5689292结构化时间:print(time.localtime()) # time.struct_time(tm_year=2021, tm_mon=5, tm_mday=28, tm_hour=13, tm_min=38, tm_sec=30, tm_wday=4, tm_yday=148, tm.原创 2021-05-28 14:02:29 · 591 阅读 · 0 评论 -
python操作excel,新建/复制/读取/写入等操作小记
导包import openpyxl往文件进行写入数据的3种方式# -*- coding: utf-8 -*-#coding=utf-8import openpyxlimport timedef testOne(): # 创建一个新的book和一个sheet mywb = openpyxl.Workbook() # 获取所有sheets的名称, sheetNames = mywb.sheetnames print("所有的sheet的名称:"+s原创 2021-05-11 09:27:02 · 1002 阅读 · 0 评论