Skip to main content

a util collection for python developing

Project description

# mountains

[![travis-ci](]( [![Coverage Status](]( [![pypi package](](


<img src="docs/icon.png" style="margin-left: auto; margin-right: auto; display: block;">

## 安装

Python 2

pip install mountains


pip3 install mountains

## 功能

1. Python 2-3 兼容,大部分代码都尽可能做了兼容
2. 日期转换,各种日期、字符串、时间戳直接的转换

### 日期转换



import time
from datetime import datetime
from mountains.datetime import converter

date_str = '2016-10-30 12:30:30'
dt = datetime(year=2016, month=10, day=30, hour=12, minute=30, second=30)
t = dt.timetuple()
ts = int(time.mktime(t))
ts_ms = int(time.mktime(t) * 1000)

# 字符串转 datetime
dt = converter.str2datetime(date_str)
# 字符串转 time
# 日期字符串转时间戳,结果为秒
# 日期字符串转时间戳,结果为毫秒
converter.str2timestamp(date_str, millisecond=True)
# datetime 转字符串,默认格式 %Y-%m-%d %H:%M:%S
# datetime 转字符串,指定格式
converter.datetime2str(dt, '%Y-%m-%d')

### 日志功能

对原生的 logging 进行了封装,使用起来更简单

from mountains import logging
from mountains.logging import StreamHandler, FileHandler, RotatingFileHandler, TimedRotatingFileHandler

# 配置日志,输出到控制台、保存到文件、日志级别、输出格式等,文件默认保存到 log.txt
logging.init_log(StreamHandler(format=logging.FORMAT_SIMPLE), FileHandler(format=logging.FORMAT_VERBOSE, level=logging.DEBUG))
# RotatingFileHandler 按文件大小分割日志文件
logging.init_log(StreamHandler(format=logging.FORMAT_SIMPLE), RotatingFileHandler(format=logging.FORMAT_VERBOSE, level=logging.DEBUG))
# TimedRotatingFileHandler 按时间分割日志文件
logging.init_log(StreamHandler(format=logging.FORMAT_SIMPLE), TimedRotatingFileHandler(format=logging.FORMAT_VERBOSE, level=logging.DEBUG))

# 使用方法与原生的 logging 一样
logger = logging.getLogger(__name__)

Project details

Download files

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

Files for mountains, version 0.6.5
Filename, size File type Python version Upload date Hashes
Filename, size mountains-0.6.5-py2.py3-none-any.whl (56.0 kB) File type Wheel Python version 3.5 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page