Skip to main content

base common lib for python

Project description

base_common_lib

常用的基础通用Lib集合

快速入门

  1. 安装
pip install baselib
  1. 创建日志文件
from baselib.log import file_logger
# 生成 logger 对象,默认自定义了日期格式,以及按天做日志分割
logger = file_logger("文件路径+名称")

logger.info("info msg")
logger.debug("debug msg")
  1. json文件读写,更新
from baselib.json import JsonFile

# 获取json格式文件,当读取异常时返回空的dict
data = JsonFile.read("文件路径+名称")

# 写入json格式文件
JsonFile.write("文件路径+名称", data)

# 直接更新文件,不需要先调用read
JsonFile.update("文件路径+名称", {"1": 2})
  1. 日期段计算 period (简化datetime的调用)
from baselib.time import Period
# 获取近一个小时的起止时间
start_time, end_time = Period.get_recent_hour(1)

# 获取当前时间
now = Period.now()

# 将当前时间转换格式
now_str = Period.formate_datetime(now)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

baselib-1.0.7.2.tar.gz (14.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page