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, ...
随机推荐
- c#泛型TryParse类型转换
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- go 调用windows dll 的方法
go 调用windows dll 的方法 ,代码如下: package main import ( "fmt" "syscall" "time&quo ...
- js实现表单
<html> <head> <title>表单页面</title> <meta http-equiv="Content- ...
- SUID、SGID、粘滞位
粘滞位(Stikybit) +t,只有用户自己可以删除自己创建文件,其他用户只能查看,不能删除. 1:创建两个用户 useradd oo ...
- centos7以rpm方法装mysql5.7及大坑
环境: CentOS Linux release 7.5.1804 (Core) Mysql版本: MySQL-5.7.17-1.el6.x86_64.rpm-bundle.tar 下载地址( ...
- C语言编程知识点
(1)预处理指令#define 声明一个常数,用以表明1年中有多少秒(忽略闰年问题):#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL 1) #defin ...
- Python基础------运算符
运算符类型 算数运算符 + 加 - 减 * 乘 / 除 %取余 ...
- vue route
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 从OsChina Git下载项目到MyEclipse中
前提是,拥有权限下载 1.进入MyEclipse,点击File-->Import,选择Git,点击“Next”,如下图: , 2.选择“URI”,点击"Next" 3.输入项 ...
- k8s学习笔记之二:使用kubeadm安装k8s集群
一.集群环境信息及安装前准备 部署前操作(集群内所有主机): .关闭防火墙,关闭selinux(生产环境按需关闭或打开) .同步服务器时间,选择公网ntpd服务器或者自建ntpd服务器 .关闭swap ...