鱼C论坛

 找回密码
 立即注册
分享 Python操作Redis相关笔记
JessiFly 2024-8-29 15:04
import redis r = redis.Redis(host='localhost',port=6379,db=0) r.mset({'name':'Bob','age':20}) values = r.mget( ) for value in values: #Redis中的value是bytes数据,python需要使用decode()转换为str或者int类型 print(value.decode('utf-8')) r.append('name','Smith') #写入文件的时候 ...
个人分类: Python|58 次阅读|0 个评论
分享 python装饰器的基本用法
JessiFly 2024-8-17 22:41
def dec(fun): def wrap(): print('before running') fun() print('after running') return wrap @dec def hello(): print('decorator running') hello() 以上 ...
个人分类: Python|55 次阅读|0 个评论
分享 python3将help命令打印的内容保存到文件中
JessiFly 2024-1-20 11:01
需要重定向默认的标准输出流stdout import sys #对输出流做备份 back = sys.stdout filepath = 'out.txt' with open(filepath,'w') as f: sys.stdout = f help(str) #还原输出流 sys.stdout = back 打包成函数: import sys def help_to_file(filepath ...
个人分类: Python|110 次阅读|0 个评论
分享 tqdm模块显示进度条
JessiFly 2021-11-5 11:09
Python版本3.6.4 以下代码在VS code和IDLE中,进度条都不能单行显示。 from time import sleep from tqdm import tqdm bar = tqdm(range(1,20)) for each in bar: bar.set_description('Processing %s' %each) sleep(1) 加入ncols参数后在VS code中可正常单行显示,而IDL ...
个人分类: Python|220 次阅读|0 个评论
分享 Python3中星号的打包和range函数的配合
JessiFly 2019-7-2 19:05
print(range(1,5)) range(1, 5) print(*range(1,5)) 1 2 3 4 print函数 只支持*args,不支持**kwargs。 def print(self,*args,sep=' ',end='\n',file=None)
个人分类: Python|527 次阅读|0 个评论

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-21 06:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部