![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
日常记录
小吴-斌
这个作者很懒,什么都没留下…
展开
-
Python 按指定时区获取时间
根据时区获取时间import datetimeimport pytz# 目标时区dateStr = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")print(dateStr) # 2021-11-09 14:00:51# 目标时区dateStr = datetime.datetime.now(tz=pytz.timezone('Asia/Jakarta')).strftime("%Y-%m-%d %H:%M:%S")print原创 2021-11-09 14:04:32 · 3843 阅读 · 0 评论 -
Python 生成随机字符串的方法
random.sample使用 random.sample指定字符生成随机字符串listRandom = [0, 1, 2, 3, 4]str = random.sample(listRandom , 2)print(str ) str = random.sample(range(0, 9), 4)print(str)range(start, stop[, step]) 函数可创建一个整数列表start: 计数从 start 开始。默认是从 0 开始。例如range(5)等价于rang原创 2021-11-08 17:52:22 · 12488 阅读 · 1 评论 -
Python 中字符串中含变量几种方法
直接拼接name = "abc"age = 25str1 = "the name is " + name + " the age is " + str(age)print(str1)使用%name = "abc"age = 25str1 = "the name is %s the age is %s" % (name, age)print(str1)使用formatname = "abc"age = 25str2 = "the name is {name_val} the ag原创 2020-06-19 09:27:56 · 3627 阅读 · 0 评论 -
Python3 对Excel表格进行读取、写入、追加
Python3 对Excel表格进行读取、写入、追加写入读取追加写入使用封装函数进行读取和写入写入# coding=UTF-8import openpyxl# 使用openpyxl写xlsx文件excelData = openpyxl.Workbook() # 新建工作簿excelData.create_sheet('Test1') # 添加页# exceltable = excelData['Test1'] # 获得指定名称页exceltable = excelData.active原创 2020-06-12 19:49:06 · 1998 阅读 · 0 评论 -
Python之requests模块讲解
先看看requests的几种请求类型get请求:requests.get(‘url’)post请求:requests.post(“url/post”)put请求:requests.put(“url/put”)delete请求:requests.delete(“url/delete”)head请求:requests.head(“url/get”)options请求:requests.options(“url/get”)Response对象使用.GET 请求发送无参数的get请求 设置超原创 2020-05-29 16:56:04 · 450 阅读 · 0 评论 -
python 引入自定义模块和外部函数库文件
1、这种最简单,外部文件跟需要调用外部文件的文件同一个包,同一目录:api------api.py------funlibrary.py这样在api.py 中引入import funlibrary 或 from funlibrary import *即可2、你的其他文件不是单个文件,或者不能如上所说放到同一目录下,而是在不同目录中,子目录api------funlibrary.pyapi.pyfrom api.funlibrary import *...原创 2020-05-27 14:39:59 · 628 阅读 · 0 评论 -
python md5加密的方法
from hashlib import md5english = 'd8hgeo-2d73k0s2'md5_str = md5(english.encode('utf8')).hexdigest()print(md5_str) # 74335cc0ff464e7006d1530260385a52# 英文加密md5_str = md5(b'123').hexdigest()print(md5_str) # 202cb962ac59075b964b07152d234b70 ...原创 2020-05-22 19:54:09 · 145 阅读 · 0 评论 -
python urllib之parse中urlencode、quote、unquote使用方法
from urllib import parseparamArr = {'type': 0, 'sex': 1}print(parse.urlencode(paramArr))paramArrSign = '12s但实际上的le'quote_text = parse.quote(paramArrSign)print(quote_text)print(parse.unquote(quote_text))原创 2020-05-22 19:42:57 · 2186 阅读 · 1 评论 -
Python中对字符串大小写的转换
利用函数进行字母的大小写转换upper():所有字母大写lower():所有字母小写capitalize():首字母大写,其他字母小写title():每个单词首字母大写,其他小写#encoding:UTF-8msg = 'bLog.CSdn.net'print(msg.upper()) #upper()函数,将所有字母都转换成大写print(msg.lower()) #lower()函数,将所有字母都转换成小写print(msg.capitalize()) #capitalize()原创 2020-05-22 17:46:06 · 655 阅读 · 0 评论 -
Python 中使用sorted、json对字典排序的方法
sorted(dic,value,reverse)dic为比较函数,value 为排序的对象(这里指键或键值),reverse:注明升序还是降序,True–降序,False–升序(默认my_dict = {'lilee':25, 'age':24, 'phone':12}print(sorted(my_dict.keys()))d = {'lilee':25, 'wangyan':21, 'liqun':32, 'age':99}# 顺序 从小到大dNew = sorted(d.items(原创 2020-05-22 17:40:47 · 6051 阅读 · 0 评论 -
python random使用生成随机字符串的方法
注意:random()是不能直接访问的,需要导入 random 模块,然后通过 random 静态对象调用该方法。import randomimport string# 随机浮点数:print(random.random())print(random.uniform(1, 10))# 随机整数randNum = random.randint(1, 100)print(randNum)# 随机选取0到100间的偶数:randNum = random.randrange(0, 101原创 2020-05-22 15:38:45 · 10334 阅读 · 0 评论 -
python 下日期和时间戳相互转换方法
时间戳转成日期import time,datetime##################################################### 时间戳转成日期###################################################### 获得当前时间时间戳now = int(time.time())#转换为其他日期格式,如:"%Y-%m-%d %H:%M:%S"timeArray = time.localtime(now)otherStyl原创 2020-05-20 15:19:34 · 1410 阅读 · 0 评论 -
Python 基础
使用list列表# 列表print('list 列表')classmats = ['one', 'two', 'three']print(classmats)# 列表个数len_list = len(classmats)print(len_list)# 获取指定索引的列表值 ,从0开始,-1表示倒数第一个print(classmats[1])p...原创 2019-08-28 11:33:00 · 81 阅读 · 0 评论 -
Python 条件判断 和循环
使用条件判断 if else# 条件派单 if elseprint('条件派单 if else')# s = input('请输入生日年号:')# birth = int(s)birth = 1991if birth > 2000: print('00后')else: print('00前')使用for循环...原创 2019-08-28 11:35:00 · 48 阅读 · 0 评论