随笔分类 -  python

摘要:Python读写文件 1.open 使用open打开文件后一定要记得调用文件对象的close()方法。比如可以用try/finally语句来确保最后能关闭文件。 file_object = open('thefile.txt') try: all_the_text = file_object.read( ) finally: file_object.close( ) 注:... 阅读全文
posted @ 2019-07-15 10:43 割肉机 阅读(273) 评论(0) 推荐(0) 编辑
摘要:将python的datetime转换为unix时间戳 将unix时间戳转换为python的datetime Python time & datetime & string 相互转换 输出结果: 阅读全文
posted @ 2019-01-11 17:27 割肉机 阅读(27987) 评论(0) 推荐(1) 编辑
摘要:python datetime和unix时间戳之间相互转换 1、代码: import time import datetime # 1、datetime转unix时间戳 # (1)、逐个打印 n = datetime.datetime.now() #当前时间 a = n.timetuple() b 阅读全文
posted @ 2019-01-04 10:19 割肉机 阅读(18497) 评论(1) 推荐(0) 编辑
摘要:1. 环境。 Python:3.6.1 Python IDE:pycharm 系统:win7 2. 简单示例 import pymongo # mongodb服务的地址和端口号mongo_url = "127.0.0.1:27017" # 连接到mongodb,如果参数不填,默认为“localhos 阅读全文
posted @ 2018-12-25 13:31 割肉机 阅读(3024) 评论(0) 推荐(0) 编辑
摘要:# -*- coding:utf-8 -*-import time now_time = int(time.time())day_time = now_time - now_time % 86400 + time.timezoneday_time_str = time.asctime(time.lo 阅读全文
posted @ 2018-12-21 15:28 割肉机 阅读(847) 评论(0) 推荐(0) 编辑
摘要:这两天做统计,需要用到当月第一天0点0分0秒的unix timestamp,上个月第一天0点的unix时间戳,三个月前月第一天的0点的Unix时间戳,六个月前当月第一天的0点的Unix时间戳,现在整理如下,看代码和执行的结果,凑了半天的结果。 __author__ = 'chunyang.wu'# 阅读全文
posted @ 2018-12-19 14:50 割肉机 阅读(2303) 评论(0) 推荐(0) 编辑
摘要:一、问题描述:Python版本是3.6.3的,在Windows下使用matplotlib绘图可以,但是在ssh远程绘图的时候报错了,错误是:RuntimeError: Invalid DISPLAY variable。 二、原因:matplotlib的默认backend是TkAgg,而FltAgg、 阅读全文
posted @ 2018-07-06 13:13 割肉机 阅读(1337) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示