SimpleDao
Python http请求
2019-05-06, 访问数: 864
http请求 def open_url(url, method='GET', headers=None, postform=None, postdata=None, timeout=10): """http请求""" try: if headers is None: headers = {} if postform is None: postform = {} if len(postform) > 0: data = urllib.urlencode(postfo...
Python windows包下载
2019-05-06, 访问数: 731
问题有时windows环境编译Python包比较困难,需要安装vc++环境,这时可以直接使用别人编译好的包。 下载地址http://www.lfd.uci.edu/~gohlke/pythonlibs/
Python xml,html转义字符
2019-05-06, 访问数: 923
xml转义字符from xml.sax.saxutils import escapedef xmlescape(data): if data is None: data = '' elif not isinstance(data, str): data = str(data) return escape(data, entities={"'": "'", '"': """}) html转义字符def html_escape(s): htmlcodes = ( ('&', '&am...
Python 安装pip,指定pip源
2019-05-06, 访问数: 937
安装pip执行命令 # 下载安装程序curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py# 安装python get-pip.py 指定pip的下载源# 指定阿里云为下载源,加速下载,解决下载失败或者缓慢的问题pip install -i https://mirrors.aliyun.com/pypi/simple/ django
Python编译安装
2019-05-06, 访问数: 762
依赖yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel cyrus-sasl cyrus-sasl-devel 安装tar zxvf Python-2.7.3.tgzcd Python-2.7.3./configuremake && make install
Python遍历文件夹
2019-05-06, 访问数: 918
followlinks表示是否扫描软连接,topdown是否广度遍历 def get_file_path(dir_path): """获取文件夹下面的所有文件,包括子文件夹""" file_list = os.walk(dir_path, topdown=True, onerror=None, followlinks=False) for root, dirs, files in file_list: for f in files: path = os.path.join(root, f) yield path....
django-cas或其它python程序,出现错误 CERTIFICATE_VERIFY_FAILEDSSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed# 增加代码,不检验自签名证书import sslssl._create_default_https_context = ssl._create_unverified_context
使用文件锁,支持linux和windowsimport osimport sysimport timeimport logginglogger = loggingclass SingleInstance: def __init__(self): py_file_path = os.path.abspath(__file__) basepath = os.path.dirname(py_file_path) self.lockfile = os.path.normpath(basepath + '/' + os.path.basename(_...
Python设置日志翻滚
2019-05-06, 访问数: 1296
可翻滚的日志: logger.py# -*- coding: utf-8 -*-import osimport loggingfrom logging.handlers import RotatingFileHandlerdef get_full_path(local_path): file_path = os.path.abspath(__file__) base_path = os.path.dirname(file_path) return os.path.join(base_path, local_path)LOG_LEVEL = logging.DEBUGLO...
Python 时间格式转换
2019-05-06, 访问数: 974
datetime和str# str转datetimedatetime.datetime.strptime('2017-04-23 00:00:00', '%Y-%m-%d %H:%M:%S')# datetime转strdatetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S');# datetime转timestamptime.mktime(dt.timetuple()) utc时间转本地时间from_zone = tz.tzutc()to_zone = tz.tzlocal()utc = datetime.strptime(utcs, '...