pythone函数基础(7)第三方模块学习
一,time模块学习
import time
# print(int(time.time()))#时间戳
# res = time.strftime('%Y-%m-%d %H:%M:%S')#取当前格式化好的时间
# print(res) #时间戳转换成时间元组,时间戳转格式化好的时间
#time1 = time.gmtime(int(time.time()))#把时间戳转成时间元组,以标准时间的时间转换的
# time1 = time.localtime(int(time.time()))#把时间戳转成时间元组,以标准时间的时间转换的
# res = time.strftime('%Y-%m-%d %H:%M:%S',time1)
# print(res) #格式化好的时间转时间戳 timep = time.strptime('2018-10-23 15:38:59','%Y-%m-%d %H:%M:%S')
print(timep)
res = time.mktime(timep)#把时间元组转成时间戳
print(res)
#20181023 2323
def timestampToStr(timestamp=None,format='%Y-%m-%d %H:%M:%S'):
#时间戳转格式化好的时间
if timestamp:
time1 = time.localtime(timestamp)
res = time.strftime(format, time1)
else:
res = time.strftime(format)
return res
#20180304153958
def strTotimestamp(str=None,format='%Y%m%d%H%M%S'):
#格式化的时间转时间戳
if str:
timep = time.strptime(str, format)
res = time.mktime(timep)
else:
res = time.time()
return int(res) 二,json模块学习
import json
#解析json的 # json_str = '''
# {"name":"xiaohei","age":18,"sex":"男","age":18}
# '''
# res = json.loads(json_str) #把字符串(json串)转成字典
# print(res)
# print(type(json_str))
# print(type(res)) dic = {
"xiaohei":{
"age":18,
"password":12345,
"sex":"男",
"addr":"北京"
},
"马春波":{
"age":18,
"password":12345,
"sex":"男",
"addr":"北京"
},
"王东泽":{
"age":18,
"password":12345,
"sex":"男",
"addr":"北京"
},
}
# res = json.dumps(dic,ensure_ascii=False,indent=4)#把字典变成字符串
# print(res)
# f = open('user.json','w',encoding='utf-8')
# f.write(res) #load 自己读
# f = open('user.json',encoding='utf-8')
# res = json.loads(f.read())
# print(res)
# res = json.load(f)
# print(res) #dump 自己写的
fw = open('newuser.json','w')
json.dump(dic,fw,indent=4,ensure_ascii=False) 三,os模块学习
import os
res = os.listdir('/Users/nhy/Desktop') #列出某个目录下的所有文件
# os.remove()
# os.rename()
# os.mkdir(r'test/niuhy/haha')#创建文件夹
# os.makedirs(r'test1/lyl/aaa')#会创建父目录
# res = os.path.exists(r'/Users/nhy/Desktop/stu.txt')
# os.path.isfile() #判断是否为文件
# os.path.isdir()#判断是否为文件
# res = os.path.split(r'/Users/nhy/Desktop/stu.txt')
# res = os.path.dirname(r'/Users/nhy/Desktop/stu.txt')#取父目录
# res = os.getcwd() #获取当前的目录
# os.chdir(r'/Users/nhy/Desktop/')#更改当前目录
# res = os.getcwd()
# print(res)
# open('a.txt','w')
# print(os.environ)#看你电脑的环境变量
#
# res = os.path.join('test','hhh','abc','a.txt')#拼接路径
# print(res)
# res= os.path.abspath('..')#根据相对路径取绝对路径
# print(res) # res = os.system('hhhsdf')#执行操作系统命令
# # print(res)
# res = os.popen('ifconfig').read()
# print('res',res)
pythone函数基础(7)第三方模块学习的更多相关文章
- Day5 - Python基础5 常用模块学习
Python 之路 Day5 - 常用模块学习 本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shel ...
- python语言(四)关键字参数、内置函数、导入第三方模块、OS模块、时间模块
一.可变参数 定义函数时,有时候我们不确定调用的时候会传递多少个参数(不传参也可以).此时,可用包裹(packing)位置参数(*args),或者包裹关键字参数(**kwargs),来进行参数传递,会 ...
- pythone函数基础(15)接口开发初识
导入需要的第三方模块 import flaskimport toolsimport json,redisimport random server = flask.Flask(__name__)#新建一 ...
- pythone函数基础(8)内置函数学习
内置函数学习# sorted# map# filter# max# sum# round# chr# ord# dir# bool# eval# exec# zipimport mathres = m ...
- Python基础5 常用模块学习
本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve xml处理 yaml处理 configpars ...
- 《C++ Primer Plus》第7章 函数——C++的编程模块 学习笔记
函数是C++的编程模块.要使用函数,必须提供定义和原型,并调用该函数.函数定义是实现函数功能的代码:函数原型描述了函数的接口:传递给函数的值的书目和种类以及函数的返回类型.函数调用使得程序将参数传递给 ...
- pythone函数基础(14)发送邮件
导入yagmail模块import yagmailusername='uitestp4p@163.com'password='houyafan123'#生成授权码,qq.163.126都是授权码 ma ...
- pythone函数基础(13)发送网络请求
需要导入urllib模块,request模块发送网络请求有两种方法 第一种方法# from urllib.request import urlopen# from urllib.parse impor ...
- pythone函数基础(12)连接Redis,写数据,读数据,修改数据
需要导入Resdis模块 import redisip = '127.0.0.1'password='123456'r = redis.Redis(host=ip,password=password, ...
随机推荐
- [随笔][Golang][golang nil 相关]
nil 是不能比较的 不同类型的nil的address是一样的 不同类型的nil是不能比较的 nil 是map, slice, pointer, channel, func, interface的零值 ...
- Vue-项目之免费课和购物车实现
调整首页细节 固定头部 App.vue中代码 <style> body{ padding: 0; margin:0; margin-top: 80px; } </style> ...
- AIUI开放平台:多轮对话返回前几轮语槽数据
编写云函数: AIUI.create("v2", function(aiui, err){ // 获取 response response = aiui.getResponse() ...
- 实验-12-JSP简单入门
参考资料 JSP实验参考文件 主要看实验任务书 实验1. 第一个HTML页面与Tomcat 实验内容:任务书中的JSP-实验1. 1.1 EclipseJEE的使用 新建Tomcat Server 新 ...
- tinycc update VERSION to 0.9.27
TinyCC全称为Tiny C Compiler, 是微型c编译器,可在linux/win/平台上编译使用. 在用代码里面使用tcc当脚本,性能比lua还快,目前已有网游服务端使用TCC脚本提高性能. ...
- 性能测试day06_需求设计的学习(性能重中之重,思维方向永远重于工具)
今天接着来学习下性能知识,本来是应该先学习一下LR的用法的,不过听完云层大大的课之后,我感觉工具没有这一篇来的重要,我们知道性能有三大步骤:负载->监控->调优,但是在这个之前我们首先要搞 ...
- 62.纯 CSS 创作一只蒸锅(感觉不好看呀)
原文地址:https://segmentfault.com/a/1190000015389338 HTML code: <!-- steamer: 蒸锅: lid: 盖子: pot: 锅 --& ...
- MATLAB——矩阵排序详解
<span style="font-size:18px;">(1)B=sort(A) 对一维或二维数组进行升序排序,并返回排序后的数组,当A为二维时,对数组每一列进行排 ...
- leetcode79
class Solution { public boolean exist(char[][] board, String word) { for(int i=0; i<board.length; ...
- C# 委托和泛型
委托定义: 委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方法的参数来进行传递,这种将方法动态地赋给参数的做法,可以避免在程序中大量使用If-Else(Switch)语句,同时使得程序具有 ...