Posts
Bingal
Cancel

python2版本 #!/usr/bin/python # encoding: utf-8 import base64 from Crypto.Cipher import AES from Crypto import Random import hashlib class AESCipher: def __init__( self, key ): self.bs ...

第一种写法 with open('file1', 'r') as f1, open('file2', 'r') as f2, open('file3', 'w') as f3: f3.write(f1.read()) f3.write(f2.read()) 第二种写法 from contextlib import nested with nested(open('f...

安装 pip install diskcache 使用 import diskcache # 设置缓存目录 cache =diskcache.Cache('/usr/tmp') # 写 cache[b'key'] = b'value' # 读 print(cache[b'key']) 官方文档

命令行调用python生成随机字符串 python -c 'import os; print(os.urandom(16).hex())' python脚本里使用 import os print(os.urandom(16).hex()) 另一种用法,可以指定使用的字符范围 import random # 数字及大小写字母组成的32位字符串 ''.join(random.sample...

生成日期字符串 import time import datetime # datetime才能到bit级别,time只能到秒 datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') time.strftime('%Y-%m-%d %H:%M:%S') 日期字符串转datetime dt = datetime.datetime....

通常使用 sed 命令打印特定行,如 # -n: 按特定格式打印 # 100p: 指打印第一百行 $ sed -n 100p Readme.md 但 sed 打印的本领,远不止于此,除了打印特定行,还可以打印一段范围的行,如 # 打印文件中第 100-120 行 $ sed -n 100,120p Readme.md # 打印文件中第 100-120 行 $ sed -n 100,...

第1种方法 session = requests.Session() session.trust_env = False response = session.get('http://httpbin.org/') 第2种方法 proxies = { "http": None, "https": None} requests.get("http://httpbin.org/", pro...

直接看代码 # 初始化日志模块 import logging import logging.handlers logger = logging.getLogger('manager') # 输出到控制台, 级别为DEBUG console = logging.StreamHandler() console.setLevel(logging.DEBUG) logger.addHand...

Trending Tags